Learn css basics in two days (2) and css basics in two days

Source: Internet
Author: User

Learn css basics in two days (2) and css basics in two days

After receiving the previous blog, two important things in css were not mentioned, namely the floating and positioning of elements.

Part 3: Floating and clearing of Elements

The previous blog has summarized this part. Please refer to the article on float and three methods to clear float in css.

Floating is also used and common in Web pages. Pay special attention to the floating clearing method.

Part 4: positioning of Elements

Element positioning is often used in actual development, especially when precise positioning is involved.

The position attribute value of an element is static by default.

Static:

The object follows the regular flow. At this time, the four positioning offset attributes will not be applied.

Relative:

The object follows the regular flow andReference its position in the regular streamThe offset of the top, right, bottom, and left positioning offset attributes does not affect any elements in the regular stream.

Absolute:

The object is out of the conventional stream. At this time, the offset attribute isIt refers to the ancestor element located closest to itself.If no ancestor element is located, it is traced back to the body element. The offset position of the box does not affect any elements in the regular stream, and its margin is not folded with any other margin.

It is often used to precisely locate div boxes.

Fixed:

Consistent with absolute, but offset positioning isRefer to Windows. When a scroll bar appears, the object does not scroll along.

This attribute is used for some fixed navigation entries on the page.

When the position value is not static, its stack level is defined by the z-index attribute. The value range of Z-index is an integer greater than or equal to 1.

 

At this point, the floating and positioning knowledge has been explained. Floating and positioning mainly solve the problem of placing elements on the page.

Supplement:

Css layout FAQ.

1. How to center an element?

Method 1: Set the margin attribute of an element to margin: 0 auto. The element is displayed in the center of the element relative to the parent element.

Method 2: Set the element to absolute positioning. The parent element is relative positioning. The left value is half of the width of the parent element, the margin-left value is half of its own, and the value is negative. The element is horizontally centered.

2. How to center the text?

Set text-align: center to center the text horizontally. Set the line-height attribute value to equal to the element height. Center them up and down.

 

This article only summarizes the basic part of css. The new features added to css3 will be summarized separately in the future.

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.