• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Orientation change and screen.width

MulliGan81

Junior Member
I noticed that changing device orientation (android phone) causes screen.width to change. For example on my Huawei android phone when in the portrait position screen.width == 360px while in landscape 640px. Taking into account that (at least as far as i know) screen.width holds device-width property value why the code below:

Code:
@media screen and (max-device-width:360px){
  div {
    background-color: green;
  }
}
@media screen and (min-device-width:361px){
  div {
    background-color: blue;
  }
}
Doesn't work?

If device-width is linked with screen.width shouldn't it's value change accordingly with the actual device orientation just like screen.width does?
 
max-device-width is the max width of the device in any orientation. It is not the current width of the device. For that you want min-width and max-width.
 
max-device-width is the max width of the device in any orientation. It is not the current width of the device. For that you want min-width and max-width.
Ok, i thought alike, but if the screen.width holds vale of device-width and do change along orientation change (what I've checked) and why device-width itself doesn't?
 
They are two different systems and two different things, unfortunately. There isn't a much better answer then that. In web dev you can't expect consistency.
 
Back
Top