CSS _ element Positioning

Source: Internet
Author: User

The core of web page layout is positioning. In CSS, we use the position attribute as the element to locate the element. After applying this attribute to the element, we can change its position in the regular document stream!

The position attribute has four values:

Static

Relative

Fixed

 

The following is the template HTML code.

<! DOCTYPE html> 

 
If no style is added, the static positioning method is used by default. The following figure shows the effect.
 
 

Use relative positioning relative

Now we want to use the relative positioning method for the second sentence "Jia shengcai is more incoherent". The relative positioning here refers to the static position relative to the original position.

Add the following style:

 

This Code sets the p border to 1 px with a width of PX and removes the padding and padding.

The displayed result is as follows:

Now let's move the second segment to the right at the position of 200px.

 

Running Effect

It can be seen that its location is changing from the original location. It just moved a bit, and its original null position is still there. Other elements have not changed !!

Use absolute positioning absolute

 

Change the position attribute value to absolute to change the positioning method to absolute positioning. Absolute positioning: it refers to positioning the body, which is also the default positioning context.

Running Effect

It can be seen that after the absolute positioning method is adopted, the original position of the element is occupied by the elements below it.

 

 

Fixed Position fixed

Fixed positioning is similar to absolute positioning. The absolute positioning element is the context, while the fixed positioning element is the browser window, so it will not move with the page rolling.

 

 

 

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.