尽可能确保文档和模板只包含 HTML 结构。
样式都放到样式表里,自定义样式在入口文件中引入,第三方样式在link标签中引入。
行为都放到脚本里。
例外:当第三包是经过HTML中直接引入的,那么相关的脚本和样式建议放在同一个template中,以避免在更改中遗漏。javascript
<script src="https://frontend-alioss.learnta.com/lib/redactor/lib/eruda/1.9.0/eruda.min.js" defer></script>
<script> window.addEventListener('DOMContentLoaded', function(event) { var UA = navigator.userAgent; var isMobile = /(android|iphone|ipad|ipod)/i.test(UA); if (isMobile) { eruda.init(); } }); </script>
复制代码
统一四个空格缩进。
在.editorconfig中定义indent。
经过prettier自动格式化。css
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
[*.md]
trim_trailing_whitespace = false
[Makefile]
indent_style = tab
复制代码
使用utf-8。且指定字符编码的 meta 必须是 head 的第一个直接子元素;html
<meta charset="utf-8"> ;
复制代码
lang属性的取值应该遵循 BCP 47 - Tags for Identifying Languages。java
问题主要在于,zh 如今不是语言code了,而是macrolang,能做为语言code的是cmn(国语)、yue(粤语)、wuu(吴语)等。jquery
<!--简体中文-->
<html lang="zh-cmn-Hans">
<!--繁体中文-->
<html lang="zh-cmn-Hant">
<!--英文-->
<html lang="en">
复制代码
样式文件用link标签引入(须要制定rel="stylesheet"
),脚本文件用script标签引入,均不须要加type属性android
<link rel="stylesheet" src="index.css" />
<script src="index.js" /> 复制代码
禁止引用http协议的静态资源,因为目前大多数都是基于https协议开发的网站,https协议的网站引用http协议的资源,会出现混合内容(mixed content)安全性问题:ios
因此,咱们引用的资源必须是https协议或者是用相对地址而不要直接引用http协议的资源。web
<!-- recommended -->
<script src="//cdn.bootcss.com/jquery/3.4.1/core.js"></script>
<!-- not recommended -->
<script src="http://cdn.bootcss.com/jquery/3.4.1/core.js"></script>
复制代码
<h1>html 注释标签的详细介绍</h1><!-- 文章标题-->
复制代码
<!-- <p>这是文章的一个段落</p> <p>这是文章的一个段落</p> -->
复制代码
<a href="demo.html">simple</a>
复制代码
<img src="demo.png" alt="demo"/>
复制代码
标签嵌套通常来讲,只要你正确的闭合和匹配开始标签和结束标签,就不会有太大的问题(只是没有按照规范来,但并不会引发渲染错误),可是有些状况必须引发咱们的重视。chrome
<a>
<a>aaa</a>
</a>
复制代码
里面不能够嵌套div、h1~h六、p、ul、ol、li、dl、dt、dd、form等。 浏览器
<p>
<div>aaa</div>
</p>
复制代码
<meta name="keywords" content="your tags" />
复制代码
<meta name="description" content="150 words" />
复制代码
面向对外用户的采用all。面向内部用户的采用none。
<!-- all:文件将被检索,且页面上的连接能够被查询; none:文件将不被检索,且页面上的连接不能够被查询; index:文件将被检索; follow:页面上的连接能够被查询; noindex:文件将不被检索; nofollow:页面上的连接不能够被查询。 -->
<meta name="robots" content="all" />
复制代码
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
复制代码
上面这行代码基本上在每一个网站中均可以看到,但具体是什么意思呢?这里稍做解释,首先,这个标签只对IE浏览器管用。
目前国内不少浏览器都采用双内核甚至多内核。那么这时候咱们最好指定咱们优先使用的内核。
<meta name="renderer" content="webkit">
复制代码
在百度移动搜索引擎中,为了更好地知足用户需求,会同时为用户提供PC网页和mobile网页,但目前受交互、兼容和流量等因素影响,PC页在移动终端中的直接浏览体验较差。所以,百度移动搜索对缺少可替代mobile资源的PC页进行格式转码,将其转换为适合手机浏览的mobile页,使其可以在移动终端浏览器有较好的浏览体验。为了最大程度改善PC页在手机上的浏览体验,转码时会去除PC页中不能在手机浏览器上浏览的内容,并改善不适用mobile的交互功能。
这是官方说明,但实际上百度颇有可能在转码时把你的页面样式弄没了,或者说给你加一条广告之类。那么,若是不但愿本身的站点被转码、依然但愿手机端用户浏览PC页该如何操做呢?可使用no-transform协议,no-transform协议为以下两种形式:
<!-- 旧版的语法 -->
<meta http-equiv="Cache-Control" content="no-transform"/>
<!-- 新版的语法,听说比较可靠,但其实即便都用了,也未必100%不转码 -->
<meta http-equiv="Cache-Control" content="no-siteapp">
<!-- 告诉百度你的页面时适配手机和pc的,不用他帮忙转 -->
<meta name="applicable-device" content="pc,mobile"/>
复制代码
禁止chrome自动翻译。
<meta name="google" value="notranslate">
复制代码
<!-- width:宽度(数值 / device-width)(范围从200 到10,000,默认为980 像素) height:高度(数值 / device-height)(范围从223 到10,000) initial-scale:初始的缩放比例 (范围从>0 到10) minimum-scale:容许用户缩放到的最小比例 maximum-scale:容许用户缩放到的最大比例 user-scalable:用户是否能够手动缩 (no,yes) -->
<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no"/>
复制代码
<meta content="telephone=no" name="format-detection" />
复制代码
<meta content="email=no" name="format-detection" />
复制代码
项目中因为种种缘由并未使用,故放在”其余“一栏中,不表明不重要,而是根据项目需求而定。
<!-- uc强制竖屏 -->
<meta name="screen-orientation" content="portrait">
<!-- QQ强制竖屏 -->
<meta name="x5-orientation" content="portrait">
<!-- UC强制全屏 -->
<meta name="full-screen" content="yes">
<!-- QQ强制全屏 -->
<meta name="x5-fullscreen" content="true">
复制代码
<!-- 启用 WebApp 全屏模式 -->
<meta name="apple-mobile-web-app-capable" content="yes" />
复制代码
<!-- content的值为default | black | black-translucent -->
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
复制代码
<meta name="apple-mobile-web-app-title" content="标题">
复制代码
<meta http-equiv="Pragma" content="no-cache">
复制代码
上述规范主要是根据项目使用场景制定,这里整理了一份通用模板,可供大多数项目使用。
<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
<!-- 编码格式 -->
<meta charset="UTF-8" />
<!-- seo 页面关键词 -->
<meta name="keywords" content="your tags" />
<!-- seo 页面描述 -->
<meta name="description" content="150 words" />
<!-- 移动端显示 -->
<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no"/> <meta http-equiv="X-UA-Compatible" content="ie=edge" />
<!-- IE浏览器使用IE最新版本渲染,若是安装了插件则使用chrome渲染 -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<!-- 多核浏览器有限使用webkit内核渲染 -->
<meta name="renderer" content="webkit" />
<!-- 移动端禁止识别手机号 -->
<meta content="telephone=no" name="format-detection" />
<!-- 移动端禁止识别邮箱 -->
<meta content="email=no" name="format-detection" />
<!-- 禁止chrome自动翻译 -->
<meta name="google" value="notranslate">
<!-- 禁止百度转码 旧版的语法 -->
<meta http-equiv="Cache-Control" content="no-transform"/>
<!-- 禁止百度转码 新版的语法,听说比较可靠,但其实即便都用了,也未必100%不转码 -->
<meta http-equiv="Cache-Control" content="no-siteapp">
<!-- 告诉百度你的页面时适配手机和pc的,不用他帮忙转 -->
<meta name="applicable-device" content="pc,mobile"/>
<!-- 搜索引擎 文件将被检索,且页面上的连接能够被查询 -->
<meta name="robots" content="all" />
<title>Document</title>
<link rel="stylesheet" src="//xxx.com/index.css" />
</head>
<body>
<h1>hello world</h1>
<script src="//xxx.com.index.js"></script>
</body>
</html>
复制代码