Make 4 columns to fit in 1 row and stack in smaller screen - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:4 Column

Description

Make 4 columns to fit in 1 row and stack in smaller screen

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">
#pl-19 #my-19-2-0, #pl-19 #my-19-2-1, #pl-19 #my-19-2-2, #pl-19 #my-19-2-3 {
   width:23.6%;
   margin:3% 0 3% 3%;
   height:401px;
}

.panel-grid.panel-no-style {
   display:inline-block;
   width:100%;
}

@media only screen and (min-width: 20px)  {
   #pl-19 #my-19-2-0, #pl-19 #my-19-2-1, #pl-19 #my-19-2-2, #pl-19 #my-19-2-3 {
      width:98%;
      float:left;
      margin:3% 0 3% 3%;
      background:red;
   }<!--from  w  ww .j a  v  a 2  s .  co  m-->
   
   #pl-19 #my-19-2-3 {
      margin-right:3%;
   }

}

@media only screen and (min-width: 480px)  {
   #pl-19 #my-19-2-0, #pl-19 #my-19-2-1, #pl-19 #my-19-2-2, #pl-19 #my-19-2-3 {
      width:48%;
      float:left;
      margin:3% 0 3% 3%;
      background:red;
   }
   
   #pl-19 #my-19-2-3 {
      margin-right:3%;
   }

}

@media only screen and (min-width: 790px)  {
   #pl-19 #my-19-2-0, #pl-19 #my-19-2-1, #pl-19 #my-19-2-2, #pl-19 #my-19-2-3 {
      width:23.4%;
      margin:3% 0 3% 3%;
      background:red;
   }
   
   #pl-19 #my-19-2-3 {
      margin-right:3%;
   }

}
</style> 
 </head> 
 <body> 
  <div id="pl-19"> 
   <div id="pg-19-2" class="panel-grid panel-no-style"> 
    <div id="my-19-2-0" class="panel-grid-cell">
      d1 
    </div> 
    <div id="my-19-2-1" class="panel-grid-cell">
      d2 
    </div> 
    <div id="my-19-2-2" class="panel-grid-cell">
      d3 
    </div> 
    <div id="my-19-2-3" class="panel-grid-cell">
      d4 
    </div> 
   </div> 
  </div>  
 </body>
</html>

Related Tutorials