Css positioning divs in a browser responsive to change background and width - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Position

Description

Css positioning divs in a browser responsive to change background and width

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">
body {<!-- w w w. j  av  a  2 s. com-->
   background:Chartreuse;
   color:yellow;
   font-family:tahoma, sans-serif;
   text-align:center;
}

#example {
   color:blue;
   padding:21px;
   margin:0 auto;
   transition:all 2s
}

@media screen and (max-width: 399px)  {
   #example {
      background:red;
      width:100%;
   }

}

@media screen and (min-width: 400px)  {
   #example {
      background:green;
      width:51%;
   }

}
</style> 
 </head> 
 <body> 
  <div id="example">
    Lorem ipsum dolor sit a 
  </div>  
 </body>
</html>

Related Tutorials