Make flex items stack next to each other - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Flex Item

Description

Make flex items stack next to each other

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">

.container {<!--from  ww w  . j  av a  2 s  .  c om-->
   display: flex;
   flex-wrap: wrap;
}
.box {
   flex: 0 0 100%;
}
.red {
   flex: 1 0 100%;
   background: red;
   height: 170px;
}
.hide-reds {
   display: none;
}
@media all and (min-width: 800px) {
   .red {
      flex-basis: 40%;
      display: block;
   }
}
.blue {
   background: blue;
}
.orange {
   background: Orange;
   height: 300px;
}
.green {
   background: green;
}
html {
   font-size: 20px;
}
.box {
   color: white;
   font-size: 100px;
   text-align: center;
   text-shadow: 4px 4px 0 rgba(0, 0, 0, 0.1);
   padding: 10px;
   margin: 5px;
}


      </style> 
 </head> 
 <body> 
  <div class="container"> 
   <div class="box blue">
     Blue 
   </div> 
   <div class="box blue">
     Blue 
   </div> 
   <div class="box orange">
     Orange 
   </div> 
   <div class="box green">
     Green 
   </div> 
   <div class="box green">
     Green 
   </div> 
   <div class="box green">
     Green 
   </div> 
   <div class="box red">
     Red 
   </div> 
   <div class="box red">
     Red 
   </div> 
   <div class="box red hide-reds">
     Red 
   </div> 
   <div class="box red hide-reds">
     Red 
   </div> 
  </div>  
 </body>
</html>

Related Tutorials