Grokking CSS for Web Development
0% completed
Next sibling combinator (+)
How do you style only the paragraph that comes right after a heading, without adding a class to it? The heading and the paragraph are not nested inside each other, so the descendant and child combinators cannot help. They sit side by side inside the same parent.
Elements that share the same parent are called siblings. In the trail article, the <h2>, the three paragraphs and the tip <div> are all siblings, because the article is the parent of each. The next-sibling combinator, a plus sign, matches an element that comes immediately after a given sibling. The selector `h2 + p
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%