Firstly, I wanted to lock the orientation to Portrait on my Webflow website, so if someone knows the solution for that, you can type it here:
text
As I see, this solution is hard to do, so, can anyone tell me how can I display certain content when a mobile device is in Landscape. Is there any code to detect when the device is in Landscape mode and than to show the message "Turn your Device in Portrait Mode for better experience"?
If anyone have the solution or knows some other post where the solution is explained, please answer.
I tried using this API https://developer.mozilla.org/en-US/docs/Web/API/ScreenOrientation/lock
and it doesn’t work
2
Answers
There is the
window.screen.orientation
that displays whether the device is on portrait or landscape modeScreenOrientation {angle: 0, type: ‘landscape-primary’, onchange: null}
Here is some documentation on the compatibility and values for the orientation:
https://developer.mozilla.org/en-US/docs/Web/API/Screen/orientation
One approach is below, using CSS media queries and with explanatory comments in the code:
JS Fiddle demo.
aspect-ratio
.background-color
.background-image
.block-size
.box-sizing
.border
.display
.flex-flow
.gap
.height
.justify-content
.list-style-type
.margin
.margin-block-end
.padding
.place-content
.text-align
.transition
.width
.