I have a paragraph as
<p id="para one" class="paragraph one">Content</p>
How does one represent the id and class with spaces in the css
When I use
#para#one{ } .paragraph.one{ }
It does not work with the css above.
You simply can't have spaces. If you use a space it means you're using two different classes.
The class name can't contain a space, but it can contain hyphens or underscores. Any tag can have multiple space-separated class names.
They are called multiple class selectors. You basically just need to make sure all the class names are connected (no spaces between them) and separated with a dot. Show activity on this post. Classes will never actually have spaces in their name.
Yes you can. You just need to understand what they are for, the class is more general and can be used several times, the id (is like your id's) you can use it only once.
Just came across this one myself (styling an existing page with no way to change the id).
This is what I used to style it by id:
p[id='para one']{ }
And, as said previously, .paragraph.one
selects two classes - this means it will also select elements with class=" one paragraph"
and class="not a paragraph this one"
.
Your class CSS is correct. You don't have a class with a space in it, you have two classes, "paragraph" and "one". Your CSS properly selects elements that have both of those classes:
.paragraph.one { color: red; }
This is a useful technique for splitting out facets of the element into separate classes that can be combined individually. Note also that <p class="one paragraph">
will match the same selector.
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