Not understanding the behaviour of position:static?

  • Thread starter Thread starter shivajikobardan
  • Start date Start date
Click For Summary
SUMMARY

The discussion clarifies the behavior of the CSS property position: static in responsive design, particularly in relation to .dropdown and .subdropdown elements. When the viewport width is less than or equal to 500px, setting position: static overrides the default position: absolute, causing the elements to stack vertically instead of aligning horizontally. This behavior is crucial for mobile responsiveness, as removing position: static leads to layout issues on smaller screens.

PREREQUISITES
  • Understanding of CSS positioning properties, specifically position: static and position: absolute
  • Familiarity with media queries in CSS
  • Knowledge of responsive web design principles
  • Basic experience with CSS selectors and properties
NEXT STEPS
  • Research CSS positioning techniques, focusing on position: relative and position: fixed
  • Explore advanced media query usage for responsive design
  • Learn about CSS Flexbox for better layout control
  • Investigate the impact of viewport units like vw and vh on responsive design
USEFUL FOR

Web developers, front-end designers, and anyone involved in creating responsive web applications will benefit from this discussion.

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

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 9 ·
Replies
9
Views
2K
Replies
9
Views
3K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 15 ·
Replies
15
Views
1K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 20 ·
Replies
20
Views
2K
  • · Replies 13 ·
Replies
13
Views
2K