Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do multiple class selectors in Stylus CSS pre-processor

Tags:

css

stylus

How do you do/can you do this in Stylus

.classA.classB {
    color: red;
}

Note, I do mean .classA.classB not .classA .classB (they're different)

I thought this would do it

.classA
    .classB
        color red

But that does this (which makes sense I guess)

.classA .classB{color:#f00}

I realise I can do this

.classA.classB
    color red

But that doesn't feel very "Stylus" and would become clumsy as/if you nested further

Thanks Jim

like image 988
Jim Avatar asked Oct 17 '13 09:10

Jim


People also ask

Can you combine multiple CSS selectors?

Cascading Style Sheets (CSS) offers many options to style web pages. CSS uses selectors to define the classes to which a particular style is applied. These selectors can also be combined for varied uses.

How do I use multiple classes in CSS?

To specify multiple classes, separate the class names with a space, e.g. <span class="left important">. This allows you to combine several CSS classes for one HTML element.

How do I select a class in CSS?

To select elements with a specific class, write a period (.) character, followed by the name of the class. You can also specify that only specific HTML elements should be affected by a class. To do this, start with the element name, then write the period (.)


1 Answers

You should use parent reference there — use an ampersand symbol (&) to define where the parent selector would go:

.classA
    &.classB
        color red

this would render to

.classA.classB{color:#f00}
like image 164
kizu Avatar answered Oct 03 '22 03:10

kizu