Tuesday, 19 April 2016

How to Use media Query in CSS to change the style according to screen width ?

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<style>
body {
    background-color:lightgreen;
}


@media only screen and (max-width:600px){
   body{
        background-color:black;

     }
}
@media only screen and (max-width: 500px) {
    body {
        background-color:lightblue;
    }
}
</style>
</head>
<body>
<p>Resize the browser window. When the width of this document is less than 500 pixels,
 the background-color is "lightblue", otherwise it is "lightgreen".</p>
</body>
</html>

It will work as....







Resize the browser window. When the width of this document is
less than 500 pixels, the background-color is "lightblue",
otherwise it is "lightgreen".

No comments:

Post a Comment