我刚开始学习HTML,在IDs/classes中的ID/classes遇到了问题。
所以,据我所知,ID是由一个#指定的。这意味着,如果我想在和ID中创建一个ID,那不是吗:
#ID1 #ID2 {
...
}
这意味着样式将只适用于ID1内部的ID2?如果我错了,请纠正我。当我在我的(非常简单的初学者)代码中使用相同的原理时,它不起作用。这是我的代码:
<!DOCTYPE html>
<html>
<head>
<title>1 May 2016</title>
<style>
#name {
color: blue;
font-family: Tahoma;
}
#parafont #1 {
font-family: Arial;
}
#parafont #2 {
font-family: Times;
}
#parafont #3 {
font-family: Courier;
}
parafont #4 {
font-family: Lucida Grande;
}
#parafont #5 {
font-family: Helvetica;
}
#test1 #6 {
color: blue;
}
</style>
</head>
<body>
<h3 id="name">Bob Bobbington</h3>
<p>1 2 3 4 5 6 7 8 9 10</p>
<p>When was this website created? Check the <b>title</b>.</p>
<h3>All animals are quite interesting...</h3>
<p id="parafont">
<span id="1">This is a test paragraph.</span>
<span id="2">Each sentence should have a different font.</span>
<span id="3">This paragraph is going to use some styling.</span>
<span id="4">Styling will change the font of each sentence.</span>
<span id="5">Let's see whether it works!</span>
</p>
<div id="test1">
<p id="6">Test</p>
</div>
</body>
</html>
非常感谢所有的帮助
将id号1
更改为以字母开头的数字。
ID
和NAME
标记必须以字母([a-Za-z])开头,并且可以是后跟任意数量的字母、数字([0-9])、连字符("-"),下划线("_")、冒号(":")和句点(".")。
ID不能首先以数字开头。此外,由于ID是特定的,因此使用嵌套来选择元素是多余的#只要使用了更具体的#id#id2,id#id2将与#id2相同。