1

What I want is like this code:

class1:hover {
    background-color: #f9f9f9;
    box-shadow: 1px 1px 8px #E0DADF;

    class2 {
        opacity:0.5;
    }
}

Is this even possible or there is any other way to make it like this?

3
  • What are you looking to accomplish by nesting? And no, plain CSS can't do this. Commented Sep 11, 2012 at 3:01
  • that when I hove class1, class2 to will also change. Commented Sep 11, 2012 at 3:03
  • @KevinSteveManingo - Is class2 located within class1 in the DOM? Commented Sep 11, 2012 at 3:05

4 Answers 4

1
.class1:hover {
    background-color: #f9f9f9;
    box-shadow: 1px 1px 8px #E0DADF;
}

.class1:hover .class2 {
    opacity: 0.5;
}

Or use a CSS preprocessor.

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

Comments

0

You'll need to use SASS or LESS.

Comments

0

In case of SASS, or SCSS, yeah this is possible. But if you want to nest the CSS Classes, you can do this way:

class1:hover{
    background-color:#f9f9f9;
    box-shadow: 1px 1px 8px #E0DADF;
}

class1:hover class2{
    opacity:0.5;
}

Comments

0

Just to add something. What you can also do, is make the element have multiple classes. For example,

<div class="class1 class2"></div>
<div class="class2"></div>

The first div element would also have the css styles of the second.

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.