-2

Regardless of where the links are in the html, if i hover over one, for example, an image could change, the background could change, or whatever... anywhere in the site.

best answer = simple way without javascript
good enough = elegant way using javascript


edit: i already know about this...

a:hover ~ #b{
    background: red;
}

"~ #b" = next siblings

"+ #b" = first next sibling

" #b" descendant of a

that just effects siblings. what if they have completely different parents?

if there's any neat tricks, website design. that's what i'm looking for.

Puddle
  • 2,993
  • 1
  • 19
  • 32

2 Answers2

0

You can use the :hover selector to style elements when you mouse over them. You can see it here.

Rajan Patil
  • 952
  • 7
  • 15
0

You'll have to use JavaScript for that. CSS cannot do this.

document.querySelector("a").addEventListener("mouseover", function(event){
    document.querySelector(".change-on-hover").classList.add("someClass");
}

document.querySelector("a").addEventListener("mouseleave", function(event){
    document.querySelector(".change-on-hover").classList.remove("someClass");
}

Change the ".change-on-hover" to a query selector for the element you want to target. "someclass" is the name of a class that will be added or removed when a link is hovered. You'll need to add your desired styles for this class in the CSS.

hostingutilities.com
  • 8,894
  • 3
  • 41
  • 51