Not understanding the behaviour of position:static?

  • Thread starter Thread starter shivajikobardan
  • Start date Start date
Click For Summary
The discussion centers on the behavior of CSS positioning, particularly the use of "position: static" in responsive design. The key point is that "position: static" is the default positioning for elements, meaning they stack vertically and do not respond to top, bottom, left, or right values. In the provided example, both the ".dropdown" and ".subdropdown" elements initially have "position: absolute," allowing the subdropdown to appear to the right due to "left: 100%." However, when the display width is reduced to 500px or less, the media query resets the position to "static," causing the elements to stack vertically and rendering the "left: 100%" ineffective. Removing "position: static" from the media query would lead to layout issues on mobile devices, highlighting the importance of understanding how CSS positioning interacts with media queries in responsive design.
shivajikobardan
Messages
637
Reaction score
54
TL;DR
position:static in dropdown and subdropdown.


I'm learning responsive design. (Make width <500px and see)

I'm talking about this line:

CSS:
.dropdown,
  .subdropdown {

    position: static;

    width: 100vw;

}



This is the behaviour I'm getting with and without position:static. But I fail to understand why? All information that I've about position:static is that it doesn't accept Top,Bottom,Left,Right values.
 
Technology news on Phys.org
position:static places the document in default. the default is one at the top of other. this sounds reasonable to me.
 
position: static is the default, there is no need to set position: static unless it is to override a different setting of position with a lower priority.

Which is exactly what is happening in the example shown, in the default CSS you are setting position: absolute on both .dropdown and .subdropdown elements, and you are setting left: 100% on subdropdown so it hangs off to the right. However in a media query which takes effect when the display width is <= 500px you are overriding this to reset position to its default value of static so now left:100% doesn't do anything and everything stacks vertically. If you remove position: static from the media query the subdropdown breaks on mobile.
 
pbuk said:
position: static is the default, there is no need to set position: static unless it is to override a different setting of position with a lower priority.

Which is exactly what is happening in the example shown, in the default CSS you are setting position: absolute on both .dropdown and .subdropdown elements, and you are setting left: 100% on subdropdown so it hangs off to the right. However in a media query which takes effect when the display width is <= 500px you are overriding this to reset position to its default value of static so now left:100% doesn't do anything and everything stacks vertically. If you remove position: static from the media query the subdropdown breaks on mobile.
thank you.
 

Similar threads