When do you separate style classes with a space? So for example: what is the difference between the following two blocks of css?
Block 1:
div { color: brown; } div.special { font-size: 18px; }
Block 2:
div { color: brown; } div .special { font-size: 18px; }
This is the HTML:
<div class="special">The quick brown fox jumps over the lazy dog.</div>
I tried both versions. Only with block 1 the text wil be in font size 18.
The class name can't contain a space, but it can contain hyphens or underscores. Any tag can have multiple space-separated class names.
A class name is an identifier—a series of characters consisting of letters, digits, underscores ( _ ) and dollar signs ( $ ) that does not begin with a digit and does not contain spaces.
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.
You separate classes by a space when you want to refer to descendant element and you concatenate them when you want to refer to a single element with multiple classes.
For example, to refer to a div with two classes, e.g. <div class="foo bar">
you could use:
div.foo.bar {...}
To refer to the child span element <div class="foo"><span class="bar">stuff</span></div>
you could use:
div.foo .bar {...}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With