If you are looking for the best simple responsive media-query example, then below these code snipped must be helpful for you.
Ingreadients :
Main Focus Point :
- CSS
- display : none | block
- @media
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>About Media Query</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<main>
<div class="box" id="box-1">
<img src="./img/mobile.png" alt="">
<p>Phone</p>
</div>
<div class="box" id="box-2">
<img src="./img/tab.png" alt="">
<p>Tablet</p>
</div>
<div class="box" id="box-3">
<img src="./img/laptop.png" alt="">
<p>Laptop</p>
</div>
<div class="box" id="box-4">
<img src="./img/big_display.png" alt="">
<p>Big Display</p>
</div>
</main>
</body>
</html>
CSS
* {
margin : 0;
padding : 0;
box-sizing : border-box;
font-family: 'Lucida Sans';
}
.box {
width : 95%;
margin : 20px auto;
text-align : center;
font-size : 22px;
padding : 20px 0;
margin-bottom: 10px;
background : tomato;
border-radius: 10px;
border : 1px dashed black;
display : none;
}
img {
width: 50%;
}
#box-1>img {
width: 200px;
}
#box-2>img {
width: 35%;
}
/* ############################################## */
/* ############# Media Query Start ############# */
/* ############################################## */
@media (max-width:480px) {
#box-1 {
display : block;
background-color: lightseagreen;
height : 500px;
}
}
@media (min-width:481px) and (max-width:850px) {
#box-2 {
display : block;
background-color: lightskyblue;
}
}
@media (min-width:851px) and (max-width:1280px) {
#box-3 {
display : block;
background-color: lightgreen;
}
}
@media (min-width:1281px) {
#box-4 {
display : block;
background-color: lightgoldenrodyellow;
}
}
Images:
Comments
Post a Comment