【发布时间】:2019-01-08 07:43:05
【问题描述】:
样式表链接正确。我已经很久没有做过 HTML/CSS 了,但是,这似乎是直截了当的。什么不正确?
.box{
width:100px;
height:100px;
}
.box #1{
border: 1px solid red;
}
.box #2{
border: 1px solid blue;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
The content of the document......
<div class = "box" id = "1"></div>
<div class = "box" id = "2"></div>
</body>
</html>
【问题讨论】:
-
选择器中的空格很重要。
-
两种方法我都试过了。
-
ID 不能以数字开头,ID #1 也不在 .box 内
-
@IlyaBursov 说清楚,ID 不能以 CSS 中的数字开头 (unless they're escaped),它们在 HTML5 中有效。