google HTML和CSS 2020版编码规范翻译(一)

本文介绍了谷歌2020年HTML和CSS编码规范,包括使用HTTPS加载资源、遵循2个空格的缩进规则、全小写编码、删除尾部空白、使用UTF-8无BOM编码以及注释的编写方式等,旨在提高代码质量和可读性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、Protocol(协议)
Use HTTPS for embedded resources where possible.
在可能的情况下,将HTTPS用于嵌入式资源。
Always use HTTPS (https:) for images and other media files, style sheets, and scripts, unless the respective files are not available over HTTPS.
对于图像和其他媒体文件、样式表和脚本,始终使用HTTPS(https:),除非各自的文件在HTTPS上不可用。

2、eneral Formatting Rules(通用格式规则)
2.1 Indentation(行首缩进)
Indent by 2 spaces at a time.
每次缩进两个空格。
Don’t use tabs or mix tabs and spaces for indentation.
不要使用制表符或混合制表符和空格进行缩进。

2.2 Capitalization(资本化)
Use only lowercase.
只使用小写。
All code has to be lowercase: This applies to HTML element names, attributes, attribute values (unless text/CDATA), CSS selectors, properties, and property values (with the exception of strings).
所有代码都必须是小写:这适用于HTML元素名称、属性、属性值(除非文本/CDATA)、CSS选择器、属性和属性值(字符串除外)。

2.3 Trailing Whitespace(尾随空白)
Remove trailing white spaces.
移除尾随的空白。
Trailing white spaces are unnecessary and can complicate diffs.
尾随的空白是不必要的,可能会使差异复杂化。

2.4 General Meta Rules(一般元规则)

2.3.1 Encoding(编码)
Use UTF-8 (no BOM).
使用UTF-8(无BOM)
Make sure your editor uses UTF-8 as character encoding, without a byte order mark.
确保编辑器使用UTF-8作为字符编码,没有字节顺序标记。
通过<metacharset=”utf-8”>在HTML模板和文档中指定编码。不要指定样式表的编码,因为它们假定为UTF-8。
(More on encodings and when and how to specify them can be found in Handling character encodings in HTML and CSS.)
(在HTML和CSS中处理字符编码时,可以找到更多关于编码以及何时和如何指定它们的信息。)

2.3.2 Comments
Explain code as needed, where possible.
在可能的情况下,根据需要解释代码。
Use comments to explain code: What does it cover, what purpose does it serve, why is respective solution used or preferred?
使用注释来解释代码:它涵盖了什么,它有什么用途,为什么各自的解决方案被使用或首选?
Append a contact (username or mailing list) in parentheses as with the format TODO(contact).
在括号中添加联系人(用户名或邮件列表),格式为Todo(联系人)。
Append action items after a colon as in TODO: action item.
在冒号后追加操作项,如Todo:action项中的。
————————————————
版权声明:本文为优快云博主「weixin_51297712」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.youkuaiyun.com/weixin_51297712/article/details/109371861

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值