2

So my problem is that I want to change my <div> background-color and my <h4> to red, either I mouse in a <div> or <h4>.

enter image description here

This is my html (without unnecessary classes).

<div>
    <a href="#"><div><span class="icon-bubbles3"></span></div></a>
    <a href="#"><h4>News</h4></a>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>

So I've been trying to apply h4:hover {color: red} then I wanted to target also also my <div> while hovering <h4>, but there is no something like "parent selector" to target my div. So how can i do this? (I don't want to wrap either <div> and <h4> with <a> tag).

Thanks!

5
  • 1
    either I mouse in a <div> or <h4> so why not use div:hover and div:hover h4 ? Commented Feb 5, 2015 at 13:10
  • Which <div> background color? I see 2, one nested in the other. Commented Feb 5, 2015 at 13:11
  • Give the parent div a class and use that as the selector Commented Feb 5, 2015 at 13:12
  • I want to have changed colors of <div> and <h4> together, either I hover <div> or <h4> Commented Feb 5, 2015 at 13:12
  • Use jquery and parent() to select the div. Commented Feb 5, 2015 at 13:13

1 Answer 1

3

First of all you need a class on your outer-most div in order to be able to directly reference this without also referencing the "inner div":

<div class="mydiv">
    <a href="#"><div><span class="icon-bubbles3"></span></div></a>
    <a href="#"><h4>News</h4></a>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>

Then you can call:

.mydiv:hover div {
   background-color:red;
}
.mydiv:hover h4 {
   color:red;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.