0

Is it possible to add conditional formatting to change class on using hover effect on a div:

.resize:hover {
   height: 360px;
   z-index: 1;

   .font_white {
   color: blue;
   }
}


.font_white{
   color: white;
}

Is it possible to override font_white while hovering div with resize class? These classes are independent div's.

2
  • The way you've presented it, this isn't possible using only CSS. Depending on your markup, you may be able to do something though. Commented Nov 14, 2016 at 20:43
  • is this font_white class div exist inside resize div? Commented Nov 14, 2016 at 20:46

3 Answers 3

1

No it's not, not using pure CSS that is.

You can use JS, but without the code of your markup, it's hard to say what the best way is.

(Of course, if the font color is to be applied inside the div you hover, it is doable using CSS only, although not the way you describe it. But I assume you want to trigger style changes across the page by hovering a div.)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I will then use JS to handle that per your sugestion, hope that one day CSS will have such future :)
0

There is no generic way to achieve that with CSS.

If you can write a selector that matches both the element that is a member of the resize class and the element that is a member of the font_white class (which you would do using a combinator such as descendant, child or sibling) then you can use the combinator to achieve it.

For example:

.resize:hover ~ .font_white { ... }

would work if your HTML looked something like:

<button class="resize">Hover Me</button>
<section id="first">...</section>
<section id="second" class="font_white">...</section>
<section id="third" class="font_white">...</section>

You would need to select apropriate combinators for your particular HTML.

Comments

0

If you rewrite your CSS, you'll see that your desired effect is possible - and achievable without redefining the style declarations of your class.

Example:

.primary-text {
color: white;
}

.resize:hover {
height: 360px;
z-index: 1;
}

.resize:hover .primary-text {
color: blue;
}

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.