0


Can I wrap a class (or id) around styling to apply it to elements only in that class?
For example, I have :

 .title {
   color: #000;
  }
  .block {
    width: 100%;
  }
  .wrapper {
    width: 90%;
  }

I'd like to create a different design for these things, if they are in a specific class. I know You can do it like so:

.specific_class .title{
   color: #fff;
}

But then I have to add it to each block. Can I do something like this?

.specific_class{
      .title {
        color: #fff;
      }
      .block {
        width: 99%;
      }
      .wrapper {
        width: 91%;
      }
}

..just to assign different styles to work, if elements are in a specific class. (I know the last example doesn't actually work).
I have a lot of these little blocks, so one "wrapping" would work and look a lot better than copy/pasting .specific_class in front of each one.

I'd like to apologize, if such question exists. I just couldn't find the correct words and find the solution, but there probably is a question like mine.

1

1 Answer 1

1

It is not possible in regular CSS. However, you might be interested in SASS, a CSS preprocessor that allows you to write nested rules (amongst other things) and compile them down to regular CSS.

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

2 Comments

Yeah. I thought so. I just wanted an outside opinion. Hoped there is some magic trick. Crap, oh well... Thanks!
Glad to help! Yeah, we all have those "Why in the world isn't this built in?!" moments.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.