media query mobile code example
Example 1: css media queries
@media only screen and (max-width: 1200px){
}
@media only screen and (max-width: 600px){
}
@media only screen and (max-width: 425px){
}
Example 2: media query for mobile view css
@media only screen and (max-width: 600px) {
body {
background-color: lightblue;
}
}
Example 3: css media query
@media (min-width: 576px) {
.selector {
background-color:#f00;
}
}
@media (min-width: 768px) {
}
@media (min-width: 992px) {
}
@media (min-width: 1200px) {
}
Example 4: media query for mobile and tablet
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
}
@media only screen
and (min-width : 321px) {
}
@media only screen
and (max-width : 320px) {
}
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
}
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape) {
}
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : portrait) {
}
@media only screen
and (min-width : 1224px) {
}
@media only screen
and (min-width : 1824px) {
}
@media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
}
@media
only screen and (max-device-width: 667px)
only screen and (-webkit-device-pixel-ratio: 2) {
}
@media
only screen and (min-device-width : 414px)
only screen and (-webkit-device-pixel-ratio: 3) {
}
@media only screen
and (-webkit-min-device-pixel-ratio: 3),
and (min-resolution: 192dpi)and (max-width:640px) {
}
Example 5: mobile tablet desktop media queries
Syntax:
@media( media feature ) {
}
The screen resolutions of different devices are listed below:
Mobile (Smartphone) max-width: 480px
Low Resolution Tablets and ipads max-width: 767px
Tablets Ipads portrait mode max-width:1024px
Desktops max-width:1280px
Huge size (Larger screen) max-width: 1281px and greater
Example 6: media query
@media only screen and (max-width: 600px) {
.class {
}
}