Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 对类/id的空间影响_Html_Css - Fatal编程技术网

Html 对类/id的空间影响

Html 对类/id的空间影响,html,css,Html,Css,如果我们在HTML的id或类中添加一些额外的空间,会有什么影响 如果我们这样写 <div class=" class1" id=" id">This is a div</div> CSS或JS会崩溃吗 JavaScript或CSS中的类或id选择会有任何影响吗?类可以有空格分隔的类,并且id需要是唯一的。实际上不允许使用空格,但浏览器仍允许使用空格 因此,处理类名中的空格时,应该使用空格分隔的类 带有空格的ID将空格作为ID的一部分

如果我们在HTML的id或类中添加一些额外的空间,会有什么影响

如果我们这样写

<div class="              class1" id="       id">This is a div</div>
CSS或JS会崩溃吗


JavaScript或CSS中的类或id选择会有任何影响吗?

类可以有空格分隔的类,并且id需要是唯一的。实际上不允许使用空格,但浏览器仍允许使用空格

因此,处理类名中的空格时,应该使用空格分隔的类

带有空格的ID将空格作为ID的一部分-如果您在访问该ID时使用空格,则浏览器允许使用空格

var byCl=document.querySelector.class1, byId=document.getElementById, byIdSpaces=document.getElementById console.logbyCl;//好啊 console.logbyId;//无效的 console.logbyIdSpaces;//好啊 console.logbyCl,byCl.innerText console.logbyIdSpaces、byIdSpaces.innerText 这是一个div /*不起作用*/ console.logdocument.getElementById; /*工作*/ console.logdocument.getElementById; /*工作*/ console.logdocument.getElementsByClassNameclass1[0]; /*工作*/ console.logdocument.querySelector'.class1'; /*工作*/ .1级{ 颜色:红色; } /*工作*/ div[id='id']{ 文本对齐:居中; } /*不起作用*/ 身份证{ 背景颜色:黄色; } /*不起作用*/ 身份证{ 字体大小:300%; }
这是一个div你试过了吗?…我当然试过了。。。我只是想了解为什么css规则起作用。。但是对于id,它不…知道为什么类选择器工作而id选择器不工作吗?