Not understanding the behaviour of position:static?

  • Thread starter shivajikobardan
  • Start date
In summary: in summary, the position:static setting on the .dropdown and .subdropdown elements in the example causes the dropdown to behave as if it is positioned at the top of the document, while the media query which takes effect when the display width is <= 500px overrides this and causes the dropdown to behave as if it is positioned at the bottom of the document.
  • #1
shivajikobardan
674
54
TL;DR Summary
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
  • #2
position:static places the document in default. the default is one at the top of other. this sounds reasonable to me.
 
  • #3
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.
 
  • #4
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.
 

1. What is position:static in CSS?

Position:static is a CSS property that specifies the default positioning of an element. This means that the element will be positioned according to the normal flow of the document.

2. Why do elements with position:static not move?

Elements with position:static do not move because this property does not allow for any positioning or movement of the element. It simply follows the normal flow of the document and is not affected by other positioning properties or values.

3. How is position:static different from other positioning properties?

Position:static is different from other positioning properties, such as position:absolute or position:relative, because it does not allow for any movement or positioning of the element. It is the default position and cannot be changed.

4. When should I use position:static?

Position:static should be used when you want an element to follow the normal flow of the document and not be affected by any other positioning properties. It is often used as the default position for elements and does not require any additional CSS code.

5. Can I override position:static with other positioning properties?

Yes, position:static can be overridden with other positioning properties, such as position:absolute or position:relative. However, it is important to note that elements with position:static do not have a z-index, so they will always be behind elements with a z-index value.

Similar threads

  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
9
Views
2K
  • Programming and Computer Science
Replies
9
Views
3K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
9
Views
3K
Replies
3
Views
860
  • Programming and Computer Science
Replies
1
Views
2K
  • Electromagnetism
Replies
20
Views
1K
Replies
28
Views
868
Replies
64
Views
3K
Back
Top