HTML specification of web front end

JavaScript language 2020-11-13 05:04:01
html specification web end


Abstract

Excellent project source code , Even if it's multi person development , Looking at the code is like one person's hand . Unified coding standard , Make the code easier to read , Easy to understand , Easy to maintain

HTML standard

Indent

Unify two space indents

Naming specification

  • class Should be named after function or content , It's not named in terms of expression ;
  • class And id The letters of words are lower case , When multiple words are formed , Use the center line - Separate ;
  • Use the only id As Javascript hook, At the same time, avoid creating no style information class;

DOCTYPE Statement

HTML The document must be accompanied by DOCTYPE Statement , And unified use HTML5 The document declaration of :

<!DOCTYPE html>

meta label

  • Unified use “UTF-8” code
<meta charset="utf-8">
  • SEO Optimize
<!-- Page keywords -->
<meta name ="keywords" content =""/>
<!-- Page description -->
<meta name ="description" content ="">
<!-- Web Author -->
<meta name ="author" content ="">
  • priority of use IE The latest version and Chrome
<meta http-equiv ="X-UA-Compatible" content ="IE = edge,chrome = 1">
  • Add a viewport to your mobile device
<!-- device-width It's the most ideal device viewport Width -->
<!-- initial-scale=1.0 It refers to the initial scaling size is 1, That is, no scaling -->
<!-- user-scalable=0 It means that the user is not allowed to zoom -->
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
  • It is forbidden to automatically identify numbers that may be in phone format on the page
<meta name="format-detection" content="telephone=no">

Team agreement :

pc End :

<meta charset="utf-8">
<meta name="keywords" content="your keywords">
<meta name="description" content="your description">
<meta name="author" content="author,email address">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
web Front end development resources Q-q-u-n: 767273102 , There are free development tools , Zero basis , Advanced video tutorial , I hope novices don't take detours

Mobile :

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no">

label

html Labels fall into the following categories :

  • Self closing label (self-closing), There is no need to close . for example :area、base、br、col、command、embed、hr、img、input、keygen、link、meta、param、source、track、wbr etc. )
  • Closed label (closing tag), It needs to be closed . for example :textarea、title、h、div、span etc.

Team agreement :

  • All elements with start and end tags must be labeled with start and end tags , Some elements that allow to omit the start tag or bundle tag should also be written with
  • Self closing tag. Don't add the end tag
  • The name of the custom tag must contain a dash (-),<x-tags><my-element> and <my-awesome-app> It's all the right names , and <tabs> and <foo_bar> It's not true . Such restrictions make HTML Parsers can tell which are standard elements , Which are custom elements
  • Custom tags must have start and close tags
  • Minimize the number of tags

Element attributes

  • Element attribute values use double quote Syntax

recommend :

<input type="text">

Not recommended :

<input type=text>
<input type='text'>

Code nesting

  • Block elements can contain inline elements or some block elements , But inline elements cannot contain block elements , It can only contain other elements of
  • Titles and paragraphs cannot contain blocks , Such as :h1、h2、h3、h4、h5、h6、p、dt
  • Blocks and inline cannot be juxtaposed , Block level elements are juxtaposed with block level elements 、 Embedded elements are juxtaposed with embedded elements
  • Some tags are fixed nesting rules , such as ul contain li、ol contain li、dl contain dt and dd wait .

Flexible use of pseudo classes

Don't let non content information contaminate your HTML, Upset the HTML structure . have access to :before、:after And pseudo class elements

recommend :

HTML Code

<!-- That is clean markup! -->
<span class="text-box">
See the square next to me?
</span>

CSS Code :

/* We use a :before pseudo element to solve the design problem of placing a colored square in front of the text content */
.text-box:before {
content: '';
display: inline-block;
width: 1rem;
height: 1rem;
background-color: red;
}

Not recommended :

HTML Code :

<!-- We should not introduce an additional element just to solve a design problem -->
<span class="text-box">
<span class="square"></span>
See the square next to me?
</span>

CSS Code :

.text-box > .square {
display: inline-block;
width: 1rem;
height: 1rem;
background-color: red;
}
web Front end development resources Q-q-u-n: 767273102 , There are free development tools , Zero basis , Advanced video tutorial , I hope novices don't take detours

Special symbols must use the escape character

Symbol describe Escape character
Space &nbsp;
< Less than &lt;
> Greater than &gt;
& and &amp;
" quotes &quot;

Pure digital input box

Use type=“tel” instead of type=“number”

<input type="tel">

Type attribute

It's not necessary for CSS、JS Specify type properties ,HTML5 By default, it already contains .

recommend :

<link rel="stylesheet" href="" >
<script src=""></script>

Not recommended :

<link rel="stylesheet" type="text/css" href="" >
<script type="text/javascript" src="" ></script>

Annotation specifications

Single-line comments

  • Generally used for simple description , Such as some state descriptions 、 Attribute description, etc
  • A space character before and after the comment , The comment is above the code to be annotated , Take a line alone

recommend :

<!-- Comment Text -->
<div>...</div>

Not recommended :

<div>...</div><!-- Comment Text -->
<div><!-- Comment Text -->
...
</div>

Module annotation

  • A space character before and after the comment
  • <!-- S Comment Text --> Indicates the beginning of the module
  • <!-- E Comment Text --> Indicates the end of the module , There is a line between modules
  • Module comments are nested within module comments ,<!-- /Comment Text -->

recommend :

<!-- S Comment Text A -->
<div class="mod_a">
<div class="mod_b">
...
</div>
<!-- /mod_b -->
<div class="mod_c">
...
</div>
<!-- /mod_c -->
</div>
<!-- E Comment Text A -->
<!-- S Comment Text D -->
<div class="mod_d">
...
</div>
<!-- E Comment Text D -->
web Front end development resources Q-q-u-n: 767273102 , There are free development tools , Zero basis , Advanced video tutorial , I hope novices don't take detours

semantic

  • No, CSS Of HTML It's a semantic system, not UI System
  • Usually , Every tag has a semantic meaning
  • Semantically HTML structure , Help the machine ( Search engine ) understand , On the other hand, when there are many people working together , Can quickly understand the developer's intention
  • It is suggested that more semantic tags should be used in the page , Instead of the entire page with div constitute

Common tag semantics :

label semantics
<p> The paragraph
<hn> title (h1~h6)
<ul> Unordered list
<ol> Ordered list
<nav> Tag navigation , Use only for important link groups in the document
<main> Main content of the page , A page can only be used once . If it is web application , Then surround its main function
<article> Define external content , The content is independent of the rest of the document
<section> Define the sections in the document (section、 section ). Like chapters 、 header 、 Footer or other parts of the document .
<aside> Define what's not in it . Such as sidebar 、 A set of links to the article 、 advertisement 、 link 、 List of related products
<header> The header usually includes the site logo 、 Main navigation 、 Site wide links and search boxes
<footer> The footer , Only when the father is body when , It's the footer of the whole page
<figure> Define independent stream content ( Images 、 Chart 、 Photo 、 Code and so on )( The default is 40px about margin)
版权声明
本文为[JavaScript language]所创,转载请带上原文链接,感谢

  1. [front end -- JavaScript] knowledge point (IV) -- memory leakage in the project (I)
  2. This mechanism in JS
  3. Vue 3.0 source code learning 1 --- rendering process of components
  4. Learning the realization of canvas and simple drawing
  5. gin里获取http请求过来的参数
  6. vue3的新特性
  7. Get the parameters from HTTP request in gin
  8. New features of vue3
  9. vue-cli 引入腾讯地图(最新 api,rocketmq原理面试
  10. Vue 学习笔记(3,免费Java高级工程师学习资源
  11. Vue 学习笔记(2,Java编程视频教程
  12. Vue cli introduces Tencent maps (the latest API, rocketmq)
  13. Vue learning notes (3, free Java senior engineer learning resources)
  14. Vue learning notes (2, Java programming video tutorial)
  15. 【Vue】—props属性
  16. 【Vue】—创建组件
  17. [Vue] - props attribute
  18. [Vue] - create component
  19. 浅谈vue响应式原理及发布订阅模式和观察者模式
  20. On Vue responsive principle, publish subscribe mode and observer mode
  21. 浅谈vue响应式原理及发布订阅模式和观察者模式
  22. On Vue responsive principle, publish subscribe mode and observer mode
  23. Xiaobai can understand it. It only takes 4 steps to solve the problem of Vue keep alive cache component
  24. Publish, subscribe and observer of design patterns
  25. Summary of common content added in ES6 + (II)
  26. No.8 Vue element admin learning (III) vuex learning and login method analysis
  27. Write a mini webpack project construction tool
  28. Shopping cart (front-end static page preparation)
  29. Introduction to the fluent platform
  30. Webpack5 cache
  31. The difference between drop-down box select option and datalist
  32. CSS review (III)
  33. Node.js学习笔记【七】
  34. Node.js learning notes [VII]
  35. Vue Router根据后台数据加载不同的组件(思考-&gt;实现-&gt;不止于实现)
  36. Vue router loads different components according to background data (thinking - & gt; Implementation - & gt; (more than implementation)
  37. 【JQuery框架,Java编程教程视频下载
  38. [jQuery framework, Java programming tutorial video download
  39. Vue Router根据后台数据加载不同的组件(思考-&gt;实现-&gt;不止于实现)
  40. Vue router loads different components according to background data (thinking - & gt; Implementation - & gt; (more than implementation)
  41. 【Vue,阿里P8大佬亲自教你
  42. 【Vue基础知识总结 5,字节跳动算法工程师面试经验
  43. [Vue, Ali P8 teaches you personally
  44. [Vue basic knowledge summary 5. Interview experience of byte beating Algorithm Engineer
  45. 【问题记录】- 谷歌浏览器 Html生成PDF
  46. [problem record] - PDF generated by Google browser HTML
  47. 【问题记录】- 谷歌浏览器 Html生成PDF
  48. [problem record] - PDF generated by Google browser HTML
  49. 【JavaScript】查漏补缺 —数组中reduce()方法
  50. [JavaScript] leak checking and defect filling - reduce() method in array
  51. 【重识 HTML (3),350道Java面试真题分享
  52. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  53. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  54. [re recognize HTML (3) and share 350 real Java interview questions
  55. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  56. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  57. 【重识 HTML ,nginx面试题阿里
  58. 【重识 HTML (4),ELK原来这么简单
  59. [re recognize HTML, nginx interview questions]
  60. [re recognize HTML (4). Elk is so simple