微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

HTML没有加载CSS文件

我完全不知道为什么这不起作用.由于某些原因,HTML文件似乎无法加载CSS,即使两者都在同一目录中.知道可能是什么问题吗?

的index.html

<!DOCTYPE html>
<html>
<head>
<title>Home Page</title>
<link rel="stylesheet" href="style.css" media="screen" />
<Meta name="viewport" content="width=1100">
</head>
<body>
<div id="main"> Hello </div>
</body>
</html>

style.css文件

body{
    background-color: #F9F9F9;
    background-image: url(images/bg3.png);
    background-position: center top;
    background-repeat: repeat;
    text-shadow: #FFFFFF 0px 1px 0px;
    font-family: "Georgia","Times",serif;
    -webkit-font-smoothing: antialiased;
}

a{
    text-decoration: none;
}

#main{
    margin: 50px auto 50px auto;
    width: 1000px;
    min-height: 500px;
    padding: 0px 20px 0px 20px;
}

以上不起作用.在index.html中添加内联css工作正常

<!DOCTYPE html>
<html>
<head>
<title>Homepage</title>
<style type="text/css" media="screen">
    body {
        background-color: #F9F9F9;
        background-image: url(images/bg3.png);
        background-position: center top;
        background-repeat: repeat;
        text-shadow: #FFFFFF 0px 1px 0px;
        font-family: "Georgia",serif;
        -webkit-font-smoothing: antialiased;
    }
    a {
        text-decoration: none;
    }
    #main {
        margin: 50px auto 50px auto;
        width: 1000px;
        min-height: 500px;
        padding: 0px 20px 0px 20px;
    }
</style>
<Meta name="viewport" content="width=1100">
</head>
<body>
    <div id="main"> Hello </div>
</body>
</html>

解决方法

type="text/css"

到你的链接标签

虽然在现代浏览器中可能不再需要这一点,但HTML4 specification声明这是必需属性.

type = content-type [CI]

This attribute specifies the style sheet language of the element’s
contents and overrides the default style sheet language. The style
sheet language is specified as a content type (e.g.,“text/css”).
Authors must supply a value for this attribute; there is no default value for this attribute.

原文地址:https://www.jb51.cc/html/231600.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐