Home >Web Front-end >CSS Tutorial >How Can I Use CSS to Clear Floats on Paragraphs Following a Specific H1?

How Can I Use CSS to Clear Floats on Paragraphs Following a Specific H1?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-12-01 11:47:14471browse

How Can I Use CSS to Clear Floats on Paragraphs Following a Specific H1?

Adjacent Sibling Selector in CSS

In CSS, the adjacent sibling selector allows you to select an element that appears immediately after another specific element. It is particularly useful for styling elements that follow a specific parent element.

Question:

You have an

tag with the class "hc-reform" and a subsequent

tag. You want to apply the clear: both; property to all

tags that come after the

.

Solution:

The adjacent sibling selector is the appropriate choice in this scenario. The correct CSS rule would be:

h1.hc-reform + p {
  clear: both;
}

This rule will select any

tag that is an immediate sibling of the

element with the class "hc-reform". Note that this syntax is not supported in IE6 or older browsers.

The above is the detailed content of How Can I Use CSS to Clear Floats on Paragraphs Following a Specific H1?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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