EN
CSS - style elements only for portrait orientation
0 points
In this article, we would like to show you how to style elements only for portrait orientation in CSS.
Quick solution:
xxxxxxxxxx
1
@media (orientation: portrait) {
2
.element {
3
/* put portrait styles here */
4
}
5
}
Where:
portrait
styles are applied to the element when the viewportwidth
<=height
.
In this example, div
element background
will be orange
on portrait
orientation (vertical) only.
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: orange;
14
}
15
}
16
17
</style>
18
</head>
19
<body>
20
<div>Web page content here...</div>
21
</body>
22
</html>