Examples of CSS relative and absolute positioning

Source: Internet
Author: User

<Style>
Body
{Margin: 30px; font-size: 9pt ;}

. A,. B,. C,. D,. e
{
Width: 100px;
Height: 100px;
Margin: 5 auto;
Color: # FFF;
Background: #000;
}
. AA,. BB,. CC,. DD,. ee
{
Top: 10px;
Left: 10px;
Width: 10px;
Height: 10px;
Overflow: hidden;
Background: # f90;
}
. B,. D,. e
{Position: relative ;}
. CC,. DD,. ee
{Position: absolute ;}
</Style>

<Div class = "A">
<Div class = "AA"> </div>
A: No postion is set. Generally, the nested relationship is not set.
</Div>

<Div class = "B">
<Div class = "BB"> </div>
B: set relative only for external Div, which is usually nested.
</Div>

<Div class = "C">
<Div class = "cc"> </div>
C: set absolute only for the inner Div. The document contains the nested relationship. The inner DIV in the page float [non-float], which is independent of the outer Div relative to the page positioning.
</Div>

<Style>
Body
{Margin: 30px; font-size: 9pt ;}

. A,. B,. C,. D,. e
{
Width: 100px;
Height: 100px;
Margin: 5 auto;
Color: # FFF;
Background: #000;
}
. AA,. BB,. CC,. DD,. ee
{
Top: 10px;
Left: 10px;
Width: 10px;
Height: 10px;
Overflow: hidden;
Background: # f90;
}
. B,. D,. e
{Position: relative ;}
. CC,. DD,. ee
{Position: absolute ;}
</Style>

<Div class = "A">
<Div class = "AA"> </div>
A: No postion is set. Generally, the nested relationship is not set.
</Div>

<Div class = "B">
<Div class = "BB"> </div>
B: set relative only for external Div, which is usually nested.
</Div>

<Div class = "C">
<Div class = "cc"> </div>
C: set absolute only for the inner Div. The document contains the nested relationship. The inner DIV in the page float [non-float], which is independent of the outer Div relative to the page positioning.
</Div>

<Div class = "D" style = "Background: # ff0000">
<Div class = "DD"> </div>
D: set relative for the external Div, and absolute for the inner Div. The inner Div floats and locates relative to the outer Div.
</Div>

<Div class = "D" style = "Background: # ff0000">
<Div class = "DD" style = "position: relative"> </div>
D: set relative for the external Div, set relative for the inner Div, and float the inner Div and locate it relative to the outer Div.
</Div>

<Div class = "E">
<Div class = "ee" style = "Left:-10px;"> </div>
E: This indicates the boundary issue. -10! = Reverse 10px spacing
</Div>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.