Not understanding the behaviour of position:static?

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

Discussion Overview

The discussion revolves around the behavior of the CSS property position: static in the context of responsive design, particularly how it affects the layout of dropdown menus when the viewport width is less than 500px. Participants explore the implications of using position: static versus other positioning values.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Debate/contested

Main Points Raised

  • One participant notes that position: static does not accept top, bottom, left, or right values, leading to confusion about its behavior.
  • Another participant explains that position: static places elements in the default stacking order, which is one on top of the other.
  • It is suggested that setting position: static is unnecessary unless overriding a different position setting with lower priority, which is relevant in the discussed example.
  • A participant describes how the default CSS applies position: absolute to the dropdown elements, causing layout issues when the media query changes the position to static for smaller screens.
  • There is a reiteration of the point that removing position: static from the media query would break the dropdown functionality on mobile devices.

Areas of Agreement / Disagreement

Participants generally agree on the default behavior of position: static and its implications in responsive design, but there is some contention regarding the necessity of explicitly setting it in certain contexts.

Contextual Notes

The discussion highlights the dependency on specific CSS rules and media queries, as well as the potential for confusion when multiple positioning values are involved. There are unresolved aspects regarding the overall layout behavior and how different settings interact.

Who May Find This Useful

Web developers and designers interested in responsive design techniques, particularly those working with CSS positioning and layout issues.

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
3K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 9 ·
Replies
9
Views
3K
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