Home > Article > Web Front-end > How Can I Style a Paragraph Following a Specific Heading Using CSS?
When working with HTML, you may encounter scenarios where you need to apply styling to specific elements that follow others in the DOM tree. In CSS, this can be achieved using the adjacent sibling selector, represented by the plus sign ( ).
In your example, you want to apply the clear: both; rule to every
tag that follows the
h1.hc-reform + p { clear: both; }
The adjacent sibling selector ensures that the clear: both; rule is applied only to
tags that immediately follow the
So, to address the issue you mentioned where the h1.hc-reform > p selector was not working, it's because that selector represents the direct child selector, which only selects
tags that are direct children of
tags are not direct children but rather following siblings, hence the h1.hc-reform p selector is the correct choice.
The above is the detailed content of How Can I Style a Paragraph Following a Specific Heading Using CSS?. For more information, please follow other related articles on the PHP Chinese website!