Show List
CSS Media Queries
CSS Media Queries allow you to apply different styles to a web page based on the characteristics of the device or screen that is rendering the page. This allows you to create responsive designs that adjust to different screen sizes and orientations.
Here are some basic examples of using CSS Media Queries:
- Screen Width: To apply styles based on the screen width, you can use the
max-width
ormin-width
media query. For example:
@media (max-width: 767px) {
body {
background-color: lightblue;
}
}
@media (min-width: 768px) {
body {
background-color: lightgray;
}
}
- Screen Height: To apply styles based on the screen height, you can use the
max-height
ormin-height
media query. For example:
@media (max-height: 499px) {
body {
background-color: lightblue;
}
}
@media (min-height: 500px) {
body {
background-color: lightgray;
}
}
- Orientation: To apply styles based on the screen orientation, you can use the
orientation
media query. For example:
@media (orientation: portrait) {
body {
background-color: lightblue;
}
}
@media (orientation: landscape) {
body {
background-color: lightgray;
}
}
- Combining Media Queries: You can also combine multiple media queries to apply styles based on multiple conditions. For example:
@media (max-width: 767px) and (orientation: portrait) {
body {
background-color: lightblue;
}
}
@media (min-width: 768px) and (orientation: landscape) {
body {
background-color: lightgray;
}
}
These are just a few examples of using CSS Media Queries. With Media Queries, you can create responsive designs that provide an optimal user experience on different devices and screen sizes.
Leave a Comment