更新:这已经解决了。我的 CSS 选择器是错误的。非常感谢所有回复的人!
我刚刚开始使用 MAMP 在本地服务器上构建站点。我曾研究过其他人的代码,但在从头开始时我是一个新手,所以请原谅我的天真。我的 CSS 文件不会应用并为我的页眉提供正确的背景颜色。我有两个样式表,style.css 和 960.css(从 960.gs 下载)。
转到 index.html 后,960.css 在页面上呈现,但找不到 style.css。它们在同一个文件夹中,并且在 index.html 上的调用完全相同。请帮忙。
我的文件结构:
-project
-styles
style.css
960.css
index.html
代码如下:
index.html
<html>
<head>
<link rel="stylesheet" type="text/css" href="/styles/style.css"/>
<link rel="stylesheet" type="text/css" href="/styles/960.css"/>
<title>title</title>
</head>
<body>
<div id="header_container" class="container_12">
<div class="grid_2">
<h1>Title</h1>
</div>
</div>
</body>
</html>
和样式.css
#header_container .container_12 {
background-color: #000000;
}
如果您不熟悉 960 网格系统,它所做的只是为它们提供 div 类和度量。您看到的 container_12 在 960.css 中,但只设置了尺寸,没有设置背景颜色,所以我认为没有必要包含 960.css,因为它很长。这可能是 MAMP 的问题,但我确信这是代码中某个地方的一个简单错误,但我一直在研究这个问题这么久,我现在只是脑残。非常感谢您的任何意见/建议。如果我没有在任何地方说清楚或者我需要更详细地解释一些事情,请告诉我!再次感谢。
最佳答案
你写的这个 CSS 选择器是错误的。
#header_container .container_12 {
background-color: #000000;
}
使用
#header_container {
background-color: #000000;
}
或
.container_12 {
background-color: #000000;
}
关于html - CSS 不在 index.html 上呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26135688/