Flexbox: 4 items per row

前端 未结 9 1077
南笙
南笙 2020-11-22 13:01

I\'m using a flex box to display 8 items that will dynamically resize with my page. How do I force it to split the items into two rows? (4 per row)?

Here is a releva

9条回答
  •  忘了有多久
    2020-11-22 13:13

    .parent-wrapper {
    	height: 100%;
    	width: 100%;
    	border: 1px solid black;
    }
    	.parent {
    	display: flex;
    	font-size: 0;
    	flex-wrap: wrap;
    	margin-right: -10px;
    	margin-bottom: -10px;
    }
    	.child {
    	background: blue;
    	height: 100px;
    	flex-grow: 1;
    	flex-shrink: 0;
    	flex-basis: calc(25% - 10px);
    }
    	.child:nth-child(even) {
    	margin: 0 10px 10px 10px;
    	background-color: lime;
    }
    	.child:nth-child(odd) {
    	background-color: orange; 
    }
    
    
    
    	
    	Document
    	
    
    
      

    ;)

提交回复
热议问题