twitter-bootstrap HTML 和 CSS 中的单引号和双引号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33697934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 23:21:11  来源:igfitidea点击:

Single versus double quotation marks in HTML & CSS

csshtmltwitter-bootstrapgoogle-webfonts

提问by vorststoom

Could anyone clarify the difference between single and double quotation marks in HTML5 & CSS.

任何人都可以澄清 HTML5 和 CSS 中单引号和双引号之间的区别。

Here's Google's contradictory use of single quotes in HTML:

这是谷歌在 HTML 中对单引号的矛盾使用:

<link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>

And CSS:

和 CSS:

font-family: 'Roboto', sans-serif;

While Bootstrap's documentation practices demonstrate the use of double quoted marks in HTML:

虽然 Bootstrap 的文档实践演示了在 HTML 中使用双引号:

<link rel="stylesheet" href="https://cdn.rawgit.com/twbs/bootstrap/v4-dev/dist/css/bootstrap.css">

And CSS:

和 CSS:

font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;

Which practice is the bestand why?

哪种做法最好为什么

EDIT: Is there any valid reasonwhy Google Fonts decided to use single quotes ?

编辑:Google Fonts 决定使用单引号有什么正当理由吗?

回答by cocoa

Either are valid, but you probably should stick to a certain style guide. For example, Google's style guidesuggest using double quotes for HTMLand single quotes for CSS. (Although Google Fonts doesn't follow this exactly)

两者都是有效的,但您可能应该坚持某种风格指南。例如,谷歌的风格指南建议使用的HTML双引号单引号的CSS。(虽然 Google Fonts 并没有完全遵循这一点)

回答by Aeolingamenfel

There's no best practice, because neither has any affect at all on how the code is parsed. You can deliminate attributes and other strings using 'or "interchangeably.

没有最佳实践,因为两者都对代码的解析方式没有任何影响。您可以使用'"可互换地分隔属性和其他字符串。

回答by Doooder

Generally, no difference. They are interchangeable.

一般来说,没有区别。它们是可以互换的。

The only important note is not to use one inside itself.

唯一重要的注意事项是不要在其内部使用一个。

For example in php:

例如在 php 中:

echo '"hello world"';

Outputs - "hello world"

输出 - “你好世界”

Or

或者

echo "'hello world'";

Outputs 'hello world'

输出“你好世界”

BUT

echo ""hello world"";

Will throw an error if the " is unescaped, as it's closing that parameter before the contents.

如果 " 未转义,则会抛出错误,因为它在内容之前关闭该参数。