我是 HTML/CSS 和这个论坛的新手。
有人能解释一下为什么下面的代码不能使文本后面的背景色变成绿色吗?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>this is my title</title>
<style>
.container {
background-color: green;
}
p {
font-family: "Helvetica", sans-serif;
font-size: 25px;
color: blue;
}
</style>
</head>
<body>
<div class=”container”>
<p>Cardigan aesthetic direct trade, migas locavore shoreditch DIY bicycle rights lyft street art bitters.</p>
</div>
</body>
</html>
如果我将其作为内联样式添加到 div 中,它会起作用吗??
(另外,我尝试先创建一个单独的样式表,然后尝试将样式添加到头部,因为这不起作用。
选择器样式起作用)。
谢谢。
最佳答案
它的“容器”
。您以这种方式为 container
使用了错误的引号 ”container”
。您应该在双引号或单引号中使用 "container"
'container'
.container {
background-color: green;
}
p {
font-family: "Helvetica", sans-serif;
font-size: 25px;
color: blue;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>this is my title</title>
</head>
<body>
<div class="container">
<p>Cardigan aesthetic direct trade, migas locavore shoreditch DIY bicycle rights lyft street art bitters.</p>
</div>
</body>
</html>
关于html - 背景颜色不适用于 HTML 元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56886700/