Search code examples
csscss-selectors

How do combine a class selector with an attribute selector? (logical AND -- must satisfy both conditions)


I have the following HTML:

<a href="somelink.htm" class="button columns large-6">wide button</a>
<a href="somelink.htm" class="button columns large-3">narrow button</a>

I've tried using an attribute selector and combining it with the button class but it doesn't work as expected.

.button.[class*="large-"] {
    font-size: 0.9em;
}

Am I using this correctly and if not, how?


Solution

  • You don't need the second period, unlike JavaScript the [class*="large-"] isn't compiled to return the found-string, it's simply evaluated as-is:

    .button[class*="large-"] {
        font-size: 0.9em;
    }
    

    JS Fiddle demo.