There are several ways of doing this but the easiest way to do it is using the sibling combinator but the text has to be next to and within the same parent element. The ~ combinator will select any sibling after the first element but has to occur after the one you hover over.
The most powerful one is the :has pseudo selector but that takes a bit of understanding and isn’t fully supported across all browsers yet.
See example below
.texta:hover + .textb {
color:red;
}
<span class="texta">My name is</span>
<span class="textb">Paul</xpan>
Edit
In the comments it was requested to do a solution where the upper text changes colour when the bottom text is hovered.
This can be done with :has. Note this doens’t work with firefox (yet!) or some mobile browsers but is okay for Chrome, Edge and Safari desktop browsers. See caniuse.com for details.
There’s also a cheeky way with display:flex by setting the flex-direction to column-reverse. You can put the h1 blocks in reverse order but the flex box reverses them in the browser. By applying the sibling rule it’ll also work that way. It might make doing changes in future a bit confusing though.
<h1><span class='texta'>Not a</span><span id="heading1" class="headingRestaurant"> restaurant</span><span class='textc'>,<br> but here for them.</span></h1>
<h3 class="textb">
<span id="heading1" class="headingRestaurant"> restaurant </span>
<span>Not a</span>
<span>but here for them.</span>
</h3>
Problem :
How can I change the textcolor of word A when the user hovers over word B? E.g. when the user hovers over the h1 “My name is”, the text of the other h1 “Paul” should change to white.
Any solutions for this issue? Thanks in advance!
Update:
I want the text “Not a” and “but here for them.” to become white when the user hovers over the word restaurant and the word “restaurant” should become red. The second part (that “restaurant” becomes red) works fine, but the first part doesn`t work