EN
CSS - style elements using media query with orientation
0 points
In this article, we would like to show you how to style elements using media query with orientation in CSS.
Quick solution:
xxxxxxxxxx
1
@media (orientation: portrait) {
2
.element {
3
/* put portrait styles here */
4
}
5
}
6
7
@media (orientation: landscape) {
8
.element {
9
/* put landscape styles here */
10
}
11
}
Where:
portret
styles are applied to element when the viewportwidth
<=height
,landscape
styles are applied to the element when the viewportwidth
>height
.
In this example, body
element background
will be yellow
on portrait
orientation (vertical) and orange
on landscape
orientation (horizontal).
xxxxxxxxxx
1
2
<html>
3
<head>
4
<style>
5
6
div {
7
width: 100%;
8
height: 500px;
9
}
10
11
@media (orientation: portrait) {
12
div {
13
background: yellow;
14
}
15
}
16
17
@media (orientation: landscape) {
18
div {
19
background: orange;
20
}
21
}
22
23
</style>
24
</head>
25
<body>
26
<div>Web page content here...</div>
27
</body>
28
</html>