我在CSS中添加了一個背景圖片到我的html元素,因此它隨着網頁瀏覽器的大小而擴展。我將這個HTML元素中的不透明度更改爲0.5。我想要將子元素(特別是h1和段落元素)更改爲不透明度爲1,以便文本不透明。它不起作用。請幫助:)將html元素的不透明度更改爲0.5後,爲什麼我不能將h1元素的不透明度更改回1?
HTML:
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<link rel = "stylesheet" href = "style.css">
</head>
<body>
<p id ="topBar"></p>
<h1>Heading</h1>
<h3>Name</h3>
<p>
Paragraph
</p>
<h3>Heading</h3>
<p>More text</p>
<h3>Send us an email!</h3>
<form>
<input style ="width:200px" type="email" placeholder ="Email" name="email"><br><br>
<textarea style ="height:100px;width:200px"placeholder = "Message" name="message"></textarea><br><br>
<input type="submit" value ="Send" name="send">
</form>
<p id ="bottomBar"></p>
</body>
</html>
CSS:
html {
background: url(pen.jpg) no-repeat center fixed;
background-size: cover;
font-family: Garamond;
text-align: center;
opacity: 0.5;
}
h1 {
opacity: 1;
}
@LaurIvan都能跟得上。 h1規則比html規則更具體,因此適用。 – JJJ
整個html文檔都有一個不透明指令,它會影響所有內容,而不管特殊性或優先級。 @LaurIvan加入!重要的是什麼也沒做您只需在特定元素上設置較低的不透明度。 –
@SLowLoris但如何? h1嵌套在html內部,因此根據css優先級,h1的規則應該覆蓋html的規則 – geeksal