CSS help

My CSS knowledge is lacking and so I'm looking for some help.

I have a basic anchor tag outside of a number of divs
e.g.
Code:
 <a class="link-wrapper"></a>
 <div>
   <div>
  
      <span class="title">some title</span>

   </div>
 </div>

The anchor is wrapped around the divs via a combination of positioning ala https://bdwm.be/html5-alternative-nested-anchor-tags/ because there is a need for a block level anchor link (e.g. a card) but the content additionally contains anchors in the contents of the div layers.

This all works in terms of the layout and links but I want to be able to underline the "title" class in the div layer
when the anchor tag has onhover, basically along the lines of
Code:
.link-wrapper:hover .title {
   text-decoration: underline;
}

but can't work out the css or if this is even possible with css alone since it is not a child of the anchor so this wont work as is.

Any help would be very appreciated.
 

Caelestian

Ars Centurion
236
Subscriptor++
My CSS knowledge is lacking
Code:
.link-wrapper:hover .title {
   text-decoration: underline;
}

but can't work out the css or if this is even possible with css alone since it is not a child of the anchor so this wont work as is.

Any help would be very appreciated.


does the sibling css selector work?

Code:
.link-wrapper:hover ~ .title {
   text-decoration: underline;
}
 

twothirdsanexplosive

Wise, Aged Ars Veteran
109
Subscriptor++
Probably way past your need now but the below code worked for me in Firefox and Chromium. Comments are my understanding though I'm no CSS pro

Code:
  /* '~ div' means that the div is a sibling of .link-wrapper on hover */
  /* '+' sibling must follow immediately after, but '~' sibling can follow at any point */
  /* and 'div span.title' descendent combinator will select with any parents between them */
  /* in case it is not necessary to be specific with the additional divs and child selectors */
  .link-wrapper:hover ~ div span.title {
     text-decoration: underline;
  }

Code:
  <a class="link-wrapper">the link wrapper</a>
  <div style="width: 30rem; height: 5rem; border: 2px solid #555">
    <div style="width: 20rem; height: 3rem; margin: 1rem; border: 1px solid #ddd">
      <span class="title">some title</span>
    </div>
  </div>

MDN is pretty clear in their reference materials if you don't know it.
https://developer.mozilla.org/en-US/doc ... _Selectors