HTML不加载CSS文件 [英] HTML not loading CSS file

查看:342
本文介绍了HTML不加载CSS文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全被解释为什么这不工作。看来HTML文件不能加载CSS的某些原因,即使两者都在同一个目录。任何想法可能是什么问题?

I am completely stumped as to why this doesn't work. It seems the HTML file can't load the CSS for some reason, even though both are in the same directory. Any idea what might be the problem?

index.html

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

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内联效果很好,但

The above doesn't work. Adding the css inline in index.html works fine though

<!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", "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;
    }
</style>
<meta name="viewport" content="width=1100">
</head>
<body>
    <div id="main"> Hello </div>
</body>
</html>


推荐答案

添加

type="text/css"

到您的链接标签

虽然在现代浏览器中可能不再需要这样做,但 HTML4规格声明这是必需属性。

While this may no longer be necessary in modern browsers the HTML4 specification declared this a required attribute.


type = content-type [CI]

type = content-type [CI]

此属性指定元素的
内容的样式表语言,并覆盖默认样式表语言。样式
表单语言被指定为内容类型(例如,text / css)。
作者必须为此属性提供值;此属性没有默认的
值。

这篇关于HTML不加载CSS文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆