Reputation: 61
The output I want is this:
#brandA, .logo{
padding: 10px;
}
What would my less code look like to achieve that output? I know about & selectors but that doesn't seem appropriate here.
Update:
I should have asked how would I write it if I wanted to nest the .logo
inside the #brandA
style I figured I can't put a comma after #brandA
like so: #brandA, { .logo{} }
because that would add the comma to all nested styles.
Upvotes: 0
Views: 152
Reputation: 89780
If I wanted to nest the
.logo
inside the#brandA
style I figured I can't put a comma after#brandA
like so:#brandA, { .logo{} }
because that would add the comma to all nested styles.
There are two things note here:
,
after #brandA
will actually not add the comma to any of the nested blocks in the latest version of the Less compiler. The compiler would just ignore the comma..logo
into #brandA
. Nesting isn't the correct way to achieve selector grouping (that is, comma separated selectors). You should either write it as-is in the question (or) use :extend
option like in the below snippet.#brandA{
padding: 10px;
&.childA{
color: red;
}
&.childB{
color: steelblue;
}
}
.logo{
&:extend(#brandA);
}
If on the other hand the .logo
element is a child (or a descendant element) of #brandA
element then you could nest it as given in Erick Boileau's latest answer. For that scenario, nesting would be a valid choice.
Upvotes: 2
Reputation: 494
#brandA {
text-align:center;
> *{
font-size:1.6rem;
}
.logo{
padding: @margin;
}
.otherClass{
a{
color:red;
}
}
}
Upvotes: 0
Reputation: 494
it's exactly the same with less , or with variable
#brandA, .logo{
padding: @margin;
}
Upvotes: 1