【问题标题】:Why is my style sheet not linking to my HTML file?为什么我的样式表没有链接到我的 HTML 文件?
【发布时间】:2016-12-16 19:40:34
【问题描述】:

所以我试图让 html 文件的背景显示为渐变。例如,像这样:http://uigradients.com/# 但是,我的样式表没有链接到我的 HTML 文件,所以不仅我的字体不起作用,而且我的渐变也不起作用。

所以基本上,这是我的索引文件在我弄乱它之前的样子:http://crwirth.github.io 基本上我要做的就是让背景变成渐变。

这是我的 HTML 文件:

<link href='https://fonts.googleapis.com/css?family=Lobster'       rel='stylesheet' type='text/css'>
<!-- CSS
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="stylesheet" type="text/css" href="index.css"  media="screen">

</head>
<!--–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<body>
    <div class="element">
            <h1><a id="line1" class="categories" title="shortblurb1"  font-family="'Lobster', cursive" font-weight="normal" text-align="left" ;>Welcome, I hope you enjoy everything you encounter here:</a></h1>
            <h2><a id="line2" class="categories" href="https://github.com/crwirth" title="shortblurb2" font-family="'Lobster', cursive" font-weight="normal" text-align="left" ;>My GitHub</a></h2>
            <h2><a id="line2" class="categories" href="https://wirthrcody.wordpress.com/" title="shortblurb2" font-family="'Lobster', cursive" font-weight="normal" text-align="left" ;>My Blog</a></h2>
            <h4><a id="line5" class="categories" href="https://twitter.com/codyrwirth" title="shortblurb5" font-family="'Lobster', cursive" font-weight="normal" text-align="left" ;>Follow me on Twitter</a></h4>
            <h5><a id="line6" class="categories" href="https://www.linkedin.com/in/wirthcodyr"title="shortblurb6" font-family="'Lobster', cursive" font-weight="normal" text-align="left" ;>Connect with me on LinkedIn</a></5>
                    <style>
                    </style>
            </div>
</body>
</html>

好的,这是我的 CSS 文件:

background: #ee0979; /* fallback for old browsers */
background: -webkit-linear-gradient(to left, #ee0979 , #ff6a00); /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to left, #ee0979 , #ff6a00); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */


html {
    background-color: #ee0979;
}

a {
    color: black;
    text-decoration: none;
    font-family: "Lobster", cursive;
    text-align: left;
}

h1 {
  color: black;
  font-family: "Lobster", cursive;
  font-size: 1.9em;
  text-align: left;
  margin-left: 15px;
  margin-top: 20px;
  padding-left: 60px;
  padding-top:  10px;
  padding-bottom: 25px;
     }

 a:hover {
    text-decoration: underline;
}


 a {
         color: black;
         font-family: "Lobster", cursive;
         font-size: 3.1em;
         text-align: left;
         padding-left: 40px;
         padding-top: 15px;
         padding-bottom: 15px;
 }

【问题讨论】:

  • 是在同一个目录吗?
  • 请检查(甚至发布)您的目录结构,如@ImAtWar 所说。此外,避免使用内联(即在您的 HTML 中)样式。它使代码不可读,重复性高,以后难以修改。

标签: html css gradient


【解决方案1】:

您问题中的代码很好,但在您的网站中存在对 css 文件的错误引用

【讨论】:

  • 好消息@JulioSilva。我建议将 href 更新为 https://crwirth.github.io/stylesheets/stylesheet.css。我检查了,文件在那里。
  • 是的,这真的很奇怪,所以我可以让它工作的唯一方法是在 HTML 文档中使用内联样式,否则我的 CSS 表只是拒绝链接到我的 HTML 文档。真正奇怪的是,当它最终喜欢我的 HTML 文档时,我注意到它会完全取消字体和渐变背景。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-25
  • 2020-10-27
  • 2019-12-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多