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.
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.
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.
class="paragraph one"
actually represents two different classes
id="para one"
won't work, but you'll probably end up having an actual id of para
You can't have spaces in id
values or class names. When you have spaces in the value of the class
attribute it specifies multiple classes that apply to that element:
<p class="paragraph one"> <!--Has both "paragraph" and "one" class-->
As for id
values, the rules (HTML4) state the following:
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
As you can see, spaces are not valid. The HTML5 spec is more leniant, but spaces are still not allowed (emphasis added):
The id attribute specifies its element's unique identifier (ID). The value must be unique amongst all the IDs in the element's home subtree and must contain at least one character. The value must not contain any space characters.
Modern browsers actually support id
with spaces. So on Chrome 54 this works:
p#para\ one {
}
And modern browsers do not support the [id="..."]
syntax, so
p[id='para one'] {
}
does not work in Chrome 54.
You simply can't have spaces. If you use a space it means you're using two different classes. One is para
and the other one is one
.