I would like to create a CSS rule for the style of span
elements that immediately follow some other range and there is no text content between them. So I want a style <span class="bar">Second</span>
in this example:
<span class="parent">
<span class="foo">First</span>
<span class="bar">Second</span>
</span>
<span class="parent">
<span class="foo">Third</span>
Some text.
<span class="bar">Fourth</span>
</span>
I tried using both +
( adjacent ) and ~
( general ) combinators without success:
span.foo+span.bar {
color: red;
}
I also tried several pseudo-classes:
span.parent :only-of-type {
color: red;
}
I am looking for some working solution in pure CSS. It may use experimental features (e.g. :has
), but they must be supported by the Chrome browser.
source
share