0

i want to add some style to the div elements when the div is not of some class

What i am trying to do? i have a div with class "card". i have other elements in the div like footer, a tag and h4. now i want to make the a, h4 tag to blue color on cursor hover.

so i do it like below,

.card a h4:hover {
    color: blue;
}

But i want to add this style to those a and h4 elements when div has only card class. i dont color blue for a, h4 elements when div has "card" and "disabled" classes. how can i do it.

below is the html code,

<div class="card">
    <div class="footer">
        <div class="info">
            <a href="somelink">
                <h4>text</h4>
            </a>
        </div>   
    </div>
</div>

Could someone help me with this. thanks.

someuser2491
  • 1,848
  • 5
  • 27
  • 63

2 Answers2

1

Hope you are looking for a solution like this. Adding style to h4 tag on hover under class card and not adding any specific style for div with both card and disabled class

.card a h4:hover {
    color: orange;
}
.card.disabled a h4:hover {
    color: inherit;
}
<div class="card">
  <div class="footer">
      <div class="info">
          <a href="">
              <h4>Card</h4>
          </a>
      </div>   
  </div>
</div>

<div class="card disabled">
  <div class="footer">
      <div class="info">
          <a href="">
              <h4>Card Disabled</h4>
          </a>
      </div>   
  </div>
</div>
Nitheesh
  • 19,238
  • 3
  • 22
  • 49
0

You can use the :not selector:

.card:not(.disabled) a h4 { ... }
isherwood
  • 58,414
  • 16
  • 114
  • 157