Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

CSS position: static property value

CSS position: static property value

CSS position Property CSS position property


position: static is the default value of the CSS position property.

when an element's position value is set to static , the element is laid out according to the document'snormal flowand arranged,not affected by top、right、bottom、left and z-index and other positioning properties.

In other words,static it means no special positioning is applied, and the element stays where it naturally belongs.

Word meaning:static comes from Latin staticus, meaning "static and motionless," indicating that the element remains in its original position.


Basic Syntax

position: static is the simplest and most basic value among CSS positioning properties.



/* 语法 */

position: static;



/* Actual example */

.box {

    position: static;

}

Property description

Attribute values Description
static default value; the element is positioned according to the normal document flow and is unaffected by positioning properties

the effect of related positioning properties on static

property effect on static elements
top Invalid, producing no positioning effect
right Invalid, producing no positioning effect
bottom Invalid, producing no positioning effect
left Invalid, producing no positioning effect
z-index Invalid, and the stacking order cannot be set manually

Example

Let's understand this through examples position: static behavior.

Example 1: static is the default positioning method

Even without explicitly setting position: static, the element is positioned as static by default. Let's compare:

Example

   

   

       

First box (default static)

       

Second box (explicit static + top:100px)

       

Third box (default static)

   

Effect description:

You will find that the second box does not move down because of top: 100px . This is because a static statically positioned element completely ignores top、right、bottom、left these positioning properties.

Example 2: static elements cannot set z-index

In the normal document flow, the stacking order of elements is determined by their order of appearance in the HTML. We cannot use z-index to change this order:

Example

   

   

       

Box 1 (z-index:999)

       

Box 2

       

Box 3

   

   

Even if Box 1 sets z-index: 999, because it is statically positioned, z-index has no effect.

   

The final stacking order is still: elements that appear later are on top (Box 3 at the top, Box 1 at the bottom).


Use Cases

Although position: static may seem to "do nothing," but it is useful in the following scenarios:

Scenario 1: Resetting positioning

When you need to cancel a previously set positioning effect, you can change position back to static:



/* Previously it might have been relative, absolute, or fixed */

.sidebar {

    position: fixed;

    top: 0;

}



/* Now we need to cancel fixed positioning and restore normal layout */

.sidebar {

    position: static;  /* 移除固定定位效果 */

}

Scenario 2: Serving as a reference for positioned children

Although static does not position itself, but it can serve as apositioning contextreference for positioned children:



/* The parent element is set to relative, even though it itself might be static */

.parent {

    position: relative;  /* 创建新的定位上下文 */

}



/* Child elements with absolute positioning will be positioned relative to this parent */

.child {

    position: absolute;

    top: 10px;

    left: 10px;

}

Scenario 3: Debugging and testing

During development, if you are unsure why an element is positioned, you can first set it back to static to troubleshoot the issue:



.debug-element {

    position: static;  /* 临时设为 static 看原始位置 */

}


Notes

Common misconceptions:Many beginners try to use top: 0、left: 0 and other properties to "reset" the element to the top-left corner, but these properties have static no effect at all on elements. If you need such an effect, you should use relative、absolute or fixed positioning.

Comparison with other positioning values

Positioning value Whether it breaks out of the document flow Whether affected by top/right/bottom/left Whether z-index is supported
static No, maintains normal layout No No
relative No, but can be offset Yes, offset relative to the original position Is
absolute Yes, removed from the document flow Yes, relative to the nearest positioned ancestor element Is
fixed Yes, removed from the document flow Yes, positioned relative to the viewport Is
sticky Yes, fixed after scrolling past the threshold Yes, at the set threshold position Is

Summary

position: static is the foundation of CSS positioning; understanding its behavior is essential for mastering other positioning methods.

Remember the following key points:


CSS position Property CSS position property