CSS Multiple Classes

SSigns

New Member
Jun 14, 2015
2
0
So I'm building a website for a client, never had to do this before but I thought that it would make sense to just do this to make the color easier to select;

I want to be able to do this in html: <div class="colourblock red/yellow/lightblue/orange etc">
Code:
  <div class="colourblock-orange">
            <div class="site-container">
            LOL
            </div>
Code:
.colourblock {
    background: #F67D42;
    width:100%;
}
Code:
.colourblock-red { }
.colourblock-yellow {}
.colourblock-lightblue {}
.colourblock-orange {}
.colourblock-green {}
.colourblock-darkblue {}
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,142
2,468
You can use spaces to give it multiple classes. <div class="colourblock red"> or <div class="colourblock yellow">

EDIT:
HTML:
<div class="colourblock orange">
      LOL
</div>

<div class="colourblock red">
      LOL
</div>

Code:
.colourblock { width: 100%; }
.colourblock .red { background-color: #ff0000; } (or just .red without the .colourblock before it, if you want to use the .red class even if there is no parent named colourblock)
 

SSigns

New Member
Jun 14, 2015
2
0
You can use spaces to give it multiple classes. <div class="colourblock red"> or <div class="colourblock yellow">

EDIT:
HTML:
<div class="colourblock orange">
      LOL
</div>

<div class="colourblock red">
      LOL
</div>

Code:
.colourblock { width: 100%; }
.colourblock .red { background-color: #ff0000; } (or just .red without the .colourblock before it, if you want to use the .red class even if there is no parent named colourblock)
Didn't work?
 

brsy

nah mang
May 12, 2011
1,530
272
Didn't work?
Code:
.colourblock { width: 100%; }
.colourblock.red { background-color: #ff0000; } (or just .red without the .colourblock before it, if you want to use the .red class even if there is no parent named colourblock)

The above should work now. Read @Sysode's explanation for why the space needs to be removed.
It wouldn't because the CSS isn't grouped, if you leave a space it isn't doing anything to the first CSS class. You either group them (no space), apply styles to multiple classes (by using a comma) or make it a child element by using (>)
 

Users who are viewing this thread

Top