html中的唯一id值 [英] unique id value in html
问题描述
<!DOCTYPE HTML PUBLIC - / / W3C // DTD HTML 4.01 // ENhttp://www.w3.org/TR/html4/strict.dtd\">
< html lang =en>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8>
< title>< / title>
< style type =text / css>
#abc {color:red; }
< / style>
< / head>
< body>
< div id =abc> Hello Div 1< / div>
< div id =abc> Hello Div 2< / div>
< / body>
< / html>
在浏览器中输出。
加载一个错误的HTML页面,它会一直在死亡。而且你不会想到很多的浏览器。
浏览器尽可能地宽容,尽可能地使用它,这是非常重要的。由于这个原因,所有的浏览器在处理标记方面往往是非常宽松的。
当然,这并不意味着你不应该写有效的HTML。 p>
This is a question more out of curiosity rather than being stuck. I know in html id needs to be unique and I can see the error in html validation. Yet the browsers happily apply style sheets to both elements. Is it because they are more relaxed in parsing or what. Does that mean I can use this for styling etc or does it have side effects.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<style type="text/css">
#abc { color: red; }
</style>
</head>
<body>
<div id="abc">Hello Div 1</div>
<div id="abc">Hello Div 2</div>
</body>
</html>
Output in browsers.
If your browser died every time it loaded an HTML page with errors, it'd be dying all the time. And you wouldn't think very much of the browser.
It's important for a browser to be as forgiving as possible and work as best it can with what it has. For this reason, all browsers tend to be very lenient in how they handle markup.
Of course, that doesn't mean you shouldn't write valid HTML.
这篇关于html中的唯一id值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!