起初,这里是代码的相关部分:无法使用ID选择器更改Bootstrap h1文本颜色?
<head>
<style type="text/css">
#part1 {
background: url("1.jpg") no-repeat center;
background-size: cover;
}
#1-title {
color: blue;
}
</style>
</head>
<body>
<div class="jumbotron jumbotron-fluid" id="part1">
<div class="container">
<h1 id="1-title" class="display-3">The New App</h1>
<p class="lead" id="1-disc">A new app</p>
<hr class="my-4">
</div>
</div>
</body>
h1
被分配“1标题”的ID,因此h1
文字颜色应该是蓝色的,但它仍然是黑色,即使我使用!important
。
不过,我尝试添加一个类,如下应用样式到它:
<style type="text/css">
#part1 {
background: url("1.jpg") no-repeat center;
background-size: cover;
}
.c {
color: blue;
}
</style>
和:
<h1 class="display-3 c">The New App</h1>
和它的工作。
那是什么原因呢?为什么我无法使用d选择器更改颜色?
选中此链接(https://www.w3.org/TR/2011/WD-html5-20110525/elements.html#the-id-attribute) –