Changing display style when use of media query - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Responsive Media

Description

Changing display style when use of media query

Demo Code

ResultView the demo in separate window

<html lang="en">
 <head> 
  <title>Lorem ipsum do</title> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <style>
@media (max-width: 400px)  {
   .container {<!--from  w w w .  j av a 2  s.com-->
      background-color:Chartreuse;
      display:flex;
      justify-content:center;
   }
   
   .header {
      background-color:yellow;
   }
   
   header {
      font-size:81px;
      padding:96px;
      font-weight:bold;
   }
   
   .p {
      background-color:blue;
   }
   
   p {
      font-size:41px;
      padding:96px;
      font-weight:bold;
   }
   
   .aside1 {
      background-color:pink;
   }
   
   .aside1_1 {
      font-size:81px;
      padding:96px;
      font-weight:bold;
   }
   
   .aside2 {
      background-color:OrangeRed;
   }
   
   .aside2_2 {
      font-size:81px;
      padding:96px;
      font-weight:bold;
   }
   
   .footer {
      background-color:grey;
   }
   
   footer {
      font-size:81px;
      padding:100px;
      font-weight:bold;
   }

}

@media (min-width:400px)  {
   body {
      background-color:BlueViolet;
      display:grid;
      grid-template-columns:26% 51% 26%;
      grid-template-rows:26% 51% 26%;
      text-align:center;
      height:801px;
   }
   
   .header {
      background-color:Chartreuse;
      grid-column:2 / 5;
      padding-top:51px;
   }
   
   header {
      font-size:41px;
      padding:21px;
      font-weight:bold;
   }
   
   .p {
      background-color:yellow;
      grid-column:3 / 4;
   }
   
   p {
      font-size:31px;
      padding:21px;
      font-weight:bold;
   }
   
   .aside1 {
      background-color:blue;
      grid-column:2/3;
      grid-row:3/4;
   }
   
   .aside1_1 {
      font-size:41px;
      padding:21px;
      font-weight:bold;
   }
   
   .aside2 {
      background-color:pink;
   }
   
   .aside2_2 {
      font-size:41px;
      padding:21px;
      font-weight:bold;
   }
   
   .footer {
      background-color:OrangeRed;
      grid-row:4 / 5;
      grid-column:2 / 5;
   }
   
   footer {
      font-size:41px;
      padding:21px;
      font-weight:bold;
      padding-top:71px;
   }

}
</style> 
 </head> 
 <body translate="no"> 
  <div class="container header"> 
   <header>
     Lorem ip 
   </header> 
  </div> 
  <div class="container p"> 
   <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi ullamcorper molestie lacus sed fermentum. Aliquam erat volutpat. Vestibulum tortor neque, ornare vitae tempor hendrerit, luctus at neque. Phasellus sed quam pharetra, tincidunt tortor in, pharetra nisl. Maecenas a</p> 
  </div> 
  <div class="container aside1"> 
   <div class="aside1_1">
     Lorem ip 
   </div> 
  </div> 
  <div class="container aside2"> 
   <div class="aside2_2">
     Lorem ip 
   </div> 
  </div> 
  <div class="container footer"> 
   <footer>
     Lorem ip 
   </footer> 
  </div>  
 </body>
</html>

Related Tutorials