0

So I have a kind of advanced CSS question:

Let's say I have following html structure:

<div id="container">
  <label id="child"></label>
</div>
<a id="stylethis"></a>

Now, I know you can style the anchor when you check for the preceding div: #container ~ #stylethis

Except, I don't want to style this if it has just a container in front of it, but rather when the container has a label with id child. So what I would have done is: #container #child ~ #stylethis

Well, problem is that this doesn't work. So my question is how can achieve something like this?

Thanks in advance,

Billy Cottrell

Billy Cottrell
  • 443
  • 5
  • 20
  • 1
    you cannot, you are missing the parent selector to go from child to container and then use `~` – Temani Afif Jul 14 '21 at 09:39
  • I just found out that it is possible with following css: `#container:has(#child) ~ #stylethis` Although that the `:has` pseudo selector is still in exerimental mode – Billy Cottrell Jul 14 '21 at 12:33

0 Answers0