0

Is it possible to make a custom rule in Css as @media I have a parent class and need to make changes depended on this class as

    <div class="parentGreen"> 
          <ul class="ul1">
            <li>1</li>
            <li>2</li>
         </ul>
         <ul class="ul2">
           <li>1</li>
          <li>2</li>
       </ul>
</div>

so when i change the parentGreen the items inside their css changes too

@parentGreen{
    ul{
direction: ltr
}
}

@parentYellow{
  ul{
direction: rtl;
margin:10px;
}
}
2
  • Use css classes inside your media selector? :/ .parentGreen ul {...} and parentYellow ul {...} Commented Feb 5, 2018 at 11:09
  • @DominicTobias i need to group them more than that Commented Feb 5, 2018 at 11:23

2 Answers 2

3

Compiled version on this link is what you want.

Do you hear about less? Try searching about it. Less is better choice for creating nested css. You can write like this:

.parent {
    .child1 {
      color: blue;
    }
    .child2 {
      color: blue;
    }
}

Look this link.

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

3 Comments

This is incorrect, the & are not needed - as it stands, .parent { &.child1 { .. } } compiles to .parent.child1 { .. } which is not right ;)
Yes, sure. Thanks for warning.
however i dont want to use a pre-processor css
1

This should work...

.parentGreen ul {
    direction: ltr
}

.parentYellow ul {
    direction: rtl;
    margin:10px;
}

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.