If it said "oneword", then I could write "#oneword", but what do I write when there is a space in the word?
如果它说“oneword”,那么我可以写“#oneword”,但是当单词中有空格时我该写什么?
6 个解决方案
#1
33
If it contains spaces, it is not legal HTML. You shouldn't expect this to work. Here is the relevant section of the HTML 4.01 specification.
如果它包含空格,则它不是合法的HTML。你不应该期望这个工作。以下是HTML 4.01规范的相关部分。
[EDIT] As others have noted, you can get around this by assigning one or more class names to the div and using a class name to do the selection.
[编辑]正如其他人所说,你可以通过为div分配一个或多个类名并使用类名进行选择来解决这个问题。
#2
29
You can't have multiple words for the id, but you can for class.
你不能为id提供多个单词,但你可以上课。
<p class="one two">lalala</p>
.one {
color: black;
}
.two {
font-weight: bold;
}
#3
6
You should not use whitespace in the ID element, as whitespace is generally accepted as a selector combinator.
您不应在ID元素中使用空格,因为空格通常被接受为选择器组合子。
#4
4
Change it to two-words. Like others said, you cannot use spaces for the id, but you can for the class.
将其更改为两个单词。像其他人说的那样,你不能为id使用空格,但你可以为这个类。
#two-words { font-family: arial; }
.center { text-align: center; }
.bold { font-weight: bold; }
<div id="two-words" class="center bold">STUFF HERE</div>
#5
1
Write Like this
写这样的
div[id='two words']{
div [id ='two words'] {
}
}
this will recognize the id as combination of both 'two' and 'words'.
这会将id识别为“两个”和“单词”的组合。
#6
0
If you make websites with IDEs like Artisteer, you can see a working id="two words"
which becomes a class
如果您使用像Artisteer这样的IDE制作网站,您可以看到一个有效的id =“两个单词”,它就变成了一个类
.two{
}
.words{
}
I don't know if this is a good practice, but it works.
我不知道这是不是一个好习惯,但它确实有效。
#1
33
If it contains spaces, it is not legal HTML. You shouldn't expect this to work. Here is the relevant section of the HTML 4.01 specification.
如果它包含空格,则它不是合法的HTML。你不应该期望这个工作。以下是HTML 4.01规范的相关部分。
[EDIT] As others have noted, you can get around this by assigning one or more class names to the div and using a class name to do the selection.
[编辑]正如其他人所说,你可以通过为div分配一个或多个类名并使用类名进行选择来解决这个问题。
#2
29
You can't have multiple words for the id, but you can for class.
你不能为id提供多个单词,但你可以上课。
<p class="one two">lalala</p>
.one {
color: black;
}
.two {
font-weight: bold;
}
#3
6
You should not use whitespace in the ID element, as whitespace is generally accepted as a selector combinator.
您不应在ID元素中使用空格,因为空格通常被接受为选择器组合子。
#4
4
Change it to two-words. Like others said, you cannot use spaces for the id, but you can for the class.
将其更改为两个单词。像其他人说的那样,你不能为id使用空格,但你可以为这个类。
#two-words { font-family: arial; }
.center { text-align: center; }
.bold { font-weight: bold; }
<div id="two-words" class="center bold">STUFF HERE</div>
#5
1
Write Like this
写这样的
div[id='two words']{
div [id ='two words'] {
}
}
this will recognize the id as combination of both 'two' and 'words'.
这会将id识别为“两个”和“单词”的组合。
#6
0
If you make websites with IDEs like Artisteer, you can see a working id="two words"
which becomes a class
如果您使用像Artisteer这样的IDE制作网站,您可以看到一个有效的id =“两个单词”,它就变成了一个类
.two{
}
.words{
}
I don't know if this is a good practice, but it works.
我不知道这是不是一个好习惯,但它确实有效。