HTML - Is it necessary to enclose a call to the css file into quotes? [duplicate]

帅比萌擦擦* 提交于 2019-12-11 14:52:42

问题


I have a .html file and ist .css file. I call the .css trough the instruction

<link rel= stylesheet href= mystyle.css>

But if I use

<link rel= "stylesheet" href= "mystyle.css">

then nothing changes in my page. Is there some difference between using the quotes or not?


回答1:


I believe the spec defines it to have quotes, but some browsers go beyond and will know what you meant.

EDIT: I was wrong! From the spec

Attributes are placed inside the start tag, and consist of a name and a value, separated by an "=" character. The attribute value can remain unquoted if it doesn't contain space characters or any of " ' ` = < or >. Otherwise, it has to be quoted using either single or double quotes. The value, along with the "=" character, can be omitted altogether if the value is the empty string.

http://www.w3.org/html/wg/drafts/html/master/introduction.html#restrictions-on-content-models-and-on-attribute-values




回答2:


In HTML5 you don't need to use quotes for any attributes. But, sometimes you have to because of knowing where a string ends. In HTML4.1 and XHTML you have to use quotes.

It's a good practice to use quotes anyway, even if you don't need them.



来源:https://stackoverflow.com/questions/17112126/html-is-it-necessary-to-enclose-a-call-to-the-css-file-into-quotes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!