起初,這裏是代碼的相關部分:無法使用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) –