【问题标题】:Linking a css file removes background链接 css 文件会删除背景
【发布时间】:2013-04-24 18:33:30
【问题描述】:

已回答此问题: 好的,我找到了解决方案。问题是 css 文档仍然包含 html 标签。感谢所有提供帮助的人。

我一直在使用 css 来设计一个网站。当 css 直接在 HTML 代码中时,该站点可以完美运行。但是,如果我将 css 保存在与 html 文件相同的目录中的外部文件中并使用标记包含它,它会保留布局但背景会消失。背景设置为图像。下面是我的css代码。

<style type="text/css">
body {
background-image: url('http://www.thepeepinghole.tk/pics/stone.jpg');
color: white;
}
#menubar {
position: relative;
width: 75%;
height: 60px;
}
#menubar svg {
margin: 0px;
width:100%;
}
#menubar h3 {
position: absolute;
top: 0px;
left: 10px;
}
#top {
height: 150px;
width: 75%;
background-color: rgba(0,0,0,0.6);
}
#top img {
position: absolute;
left: 11%;
top: -2%;
width: 266px;
height: 200px;
width: auto;
z-index: 2;
}
#top img.mirror {
position: absolute;
left: 69%;
top: -2%;
width: 266px;
height: 200px;
width: auto;
z-index: 2;
-moz-transform: scaleX(-1);
-o-transform: scaleX(-1);
-webkit-transform: scaleX(-1);
transform: scaleX(-1);
filter: FlipH;
-ms-filter: "FlipH";
}
#top h2 {
position: relative;
top: 30%;
}
#top h1 {
position: relative;
top: 30%;
}
#menubar a {
color: white;
}
#menubar img {
position: absolute;
top: 0px;
left: 85%;
float: right;
}
#content {
width: 75%;
background: rgba(0,0,0,0.6);
}
</style>

我用这段代码将它包含在我的 html 的头部:

<rel link="StyleSheet" href="http://thepeepinghole.tk/mainpage.css" type="text/css" />

【问题讨论】:

  • 网络检查器应该有助于显示样式的层次结构。
  • 您是否链接了任何其他 CSS 文件?其中一个可能会覆盖这一点。
  • @Barmar 是的,这可能是问题:D
  • 如果 EinerS 回答不起作用,您可以链接任何文件吗?
  • 没有其他css文件只有那个。也许我没有正确链接它。如果有人可以提供一个例子,它可能会有所帮助。

标签: html css file hyperlink include


【解决方案1】:

检查是否有另一个 css 规则覆盖外部文件中写入的 css 规则。

例子:

<rel link="StyleSheet" src="file.css" media="all" type="text/css"
 />
<style>
.background{
//if here is another css rule with the same class or id, this will override the one that is in the external file.
}
</style>

【讨论】:

  • 哦,我明白了,但是当我尝试使用外部文件时,我的 html 中没有任何其他样式。
  • 如果您使用的是chrome,请按f12打开控制台并查看是否找到文件。
【解决方案2】:

看起来你的语法是问题: 应该是:

<link rel="stylesheet" href="http://thepeepinghole.tk/mainpage.css" type="text/css">

不是

<rel link="stylesheet"...>

【讨论】:

  • 感谢这确实有助于最终解决方案
猜你喜欢
  • 2016-02-29
  • 1970-01-01
  • 2020-01-21
  • 1970-01-01
  • 1970-01-01
  • 2018-11-27
  • 2013-11-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多