2

i want to make a dropdown menu on butto hover, but when hovered, the effect are not applying to any other element like div or body.
this is the code

here is a link to my code if you really like to dive in search for dropbtn:hover

.dropbtn:hover .dropdown-content {
  background: green ; //tried !important also not working
  display:block;
 }
2
  • To apply style to .dropbtn:hover AND to .dropdown-content you should separate them with comma: .dropbtn:hover, .dropdown-content {...} Commented Jul 24, 2017 at 5:41
  • i want to change .dropdown-content ,background and display. when hovering .dropbtn Commented Jul 24, 2017 at 5:43

2 Answers 2

3

Your dropdown-content is not a child of your .dropbtn, so .dropbtn:hover .dropdown-content won't work. You could use + selector:

&:hover {
  & + .dropdown-content{
     background: green;
     display:block;
  }
Sign up to request clarification or add additional context in comments.

Comments

1

The selector is no good, .dropbtn:hover .dropdown-content, means that your .dropdown-content should be contained by .dropbtn, in the HTML they are next to each other. You should change the HTML to make .dropdown-content child of .dropbtn, or you could change the selector into .dropbtn:hover + .dropdown-content

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.