我完全不知道为什么这不起作用.由于某些原因,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.