Home > Web Front-end > CSS Tutorial > What is the role of clear in css

What is the role of clear in css

下次还敢
Release: 2024-04-26 10:27:13
Original
890 people have browsed it

The clear attribute in CSS is used to clear the impact of floating elements on subsequent elements to ensure that subsequent elements are arranged normally. The clear attribute has 4 values: none: Do not clear floats left: Clear left floats right: Clear right floats both: Clear left and right floats

What is the role of clear in css

The role of clear in CSS

In CSS layout, the clear attribute is used to clear the impact of floating elements on subsequent elements. Floating elements will affect the position of their subsequent elements, causing subsequent elements to not be arranged normally.

Clear floats

The clear property has the following values:

  • none: Does not clear any floats.
  • left: Clear the floating elements on the left.
  • right: Clear the floating elements on the right.
  • both: Clear the floating elements on the left and right sides.

Usage scenarios

When you need subsequent elements to be arranged normally under the floating element, you can use the clear attribute. For example:

<code class="css">.container {
  width: 100%;
}

.float-left {
  float: left;
  width: 50%;
}

.clear {
  clear: both;
}</code>
Copy after login

In this example, the .float-left element floats on the left, and the .clear element clears the influence of the floating element through clear: both, so that subsequent elements can be arranged normally.

Example

The following picture is an example of using the clear attribute:

[The picture shows two elements, the left element is floating and the right element is Use clear: both]

Use clear: both

[The picture shows that the floating elements are cleared and the elements on the right are arranged normally]

The above is the detailed content of What is the role of clear in css. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template