Using media query to change background - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Responsive Media

Description

Using media query to change background

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">
#image {<!-- w ww. j av a2s  .  c om-->
   background:url('https://www.java2s.com/style/demo/Google-Chrome.png');
   background-color:Chartreuse;
}

@media screen and (min-width:300px)  {
   #image {
      background:url('https://www.java2s.com/style/demo/Google-Chrome.png');
      background-color:yellow;
   }

}
</style> 
 </head> 
 <body> 
  <div id="image">
    &nbsp; 
  </div> 
  <div id="image"> 
  </div> 
  <div id="image" style="width:20px;height:20px"> 
  </div>  
 </body>
</html>

Related Tutorials