Make flex items wrap two at a time - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Flex Wrap

Description

Make flex items wrap two at a time

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <style id="compiled-css" type="text/css">

.line{<!--from   ww  w  . j  a v a2s .c o  m-->
   display:flex;
   width:100%;
   margin-bottom:30px;
   flex-wrap:wrap;
   align-items:center;
   justify-content:center;
}
body,html{
   margin:0;
   padding:0;
   position:relative;
}
*{
   box-sizing:border-box;
}
.box{
   width:200px;
   min-width:200px;
   background:blue;
   margin:0 10px 0 10px;
   height:200px;
}
@media ( max-width: 800px ) {
   .box { flex-basis: calc(50% - 20px); margin: 10px; }
}


      </style> 
 </head> 
 <body> 
  <div class="line"> 
   <div class="box"></div> 
   <div class="box"></div> 
   <div class="box"></div> 
   <div class="box"></div> 
  </div> 
  <div class="line"> 
   <div class="box"></div> 
   <div class="box"></div> 
   <div class="box"></div> 
   <div class="box"></div> 
  </div>  
 </body>
</html>

Related Tutorials