Languages

CSS - how to detect orientation for media queries?

0 points
Asked by:
nickkk0
647

Is there any way to detect device orientation in CSS? I need it for media queries in my project.

Something like:

1 answer
0 points
Answered by:
Admin Dirask Community
4380

Quick solution:

 

Practical example

In this example, div element background will be yellow on portrait orientation (vertical) and orange on landscape orientation (horizontal).

 

References

  1. orientation - CSS: Cascading Style Sheets | MDN
0 commentsAdd comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join