样式缺少必需属性

时间:2015-11-29 12:29:32

标签: html css

<!doctype html>
<html>
<title>some title</title>
<link href="index.css" rel="stylesheet">
<style>
// some styles...
</style>

<body>
<style>
// some styles...
</style>
...

</body
</html>

使用w3c validation service我收到了错误消息:

Element style is missing required attribute

缺少什么?

3 个答案:

答案 0 :(得分:2)

问题是<style>位于body内。

<!doctype html>
<html>
<title>some title</title>
<link href="index.css" rel="stylesheet">
<style>
// some styles...
</style>
<body>


</body>
</html>

或者您可以使用scoped属性,该属性允许您在<style>元素中放置<body>个标记,但跨浏览器兼容性仍然非常糟糕http://caniuse.com/#search=scoped

<!doctype html>
<html>
<title>some title</title>
<link href="index.css" rel="stylesheet">
<style>
// some styles...
</style>
<body>
<style type="text/css" scoped>
// some styles...
</style>
</body>
</html>

答案 1 :(得分:-2)

我相信你的标签应该有type =“text / css”属性。

答案 2 :(得分:-2)

查看修复程序。

<link type="text/css" href="index.css" rel="stylesheet">

<style type="text/css">

</body> //身体未关闭

相关问题