HTML规范有哪些

发布时间:2021-11-06 14:18:49 作者:iii
来源:亿速云 阅读:124

本篇内容主要讲解“HTML规范有哪些”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“HTML规范有哪些”吧!

HTML 规范

缩进

统一两个空格缩进

命名规范

DOCTYPE 声明

HTML 文件必须加上 DOCTYPE 声明,并统一使用 HTML5 的文档声明:

<!DOCTYPE html>

meta 标签

<meta charset="utf-8">
<!-- 页面关键词 -->
<meta name ="keywords" content =""/>
<!-- 页面描述 -->
<meta name ="description" content ="">
<!-- 网页作者 -->
<meta name ="author" content ="">
<meta http-equiv ="X-UA-Compatible" content ="IE = edge,chrome = 1">
<!-- device-width 是指这个设备最理想的 viewport 宽度 -->
<!-- initial-scale=1.0 是指初始化的时候缩放大小是1,也就是不缩放 -->
<!-- user-scalable=0 是指禁止用户进行缩放 -->
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no">

团队约定:

pc 端:

<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">

移动端:

<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">

标签

html 标签分为以下几类:

团队约定:

元素属性

推荐:web前端开发直播教程Q-q-u-n: 767273102 ,内有免费开发工具,零基础,进阶视频教程,希望新手少走弯路

<input type="text">
复制代码

不推荐:

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

代码嵌套

灵活使用伪类

不要让非内容信息污染了你的 HTML,打乱了 HTML 结构。可以使用:before、:after 等伪类元素

推荐:

HTML 代码

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

CSS 代码:

/* 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;
}

不推荐:

HTML 代码:

<!-- 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 代码:

.text-box > .square {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  background-color: red;
}

特殊符号必须使用转义符

符号描述转义符

空格&nbsp;
<小于&lt;
>大于&gt;
&&amp;
"引号&quot;

纯数字输入框

使用 type="tel" 而不是 type="number"

<input type="tel">

类型属性

不需要为 CSS、JS 指定类型属性,HTML5 中默认已包含。

推荐:

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

不推荐:

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

注释规范

单行注释

推荐:web前端开发直播教程Q-q-u-n: 767273102 ,内有免费开发工具,零基础,进阶视频教程,希望新手少走弯路

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

不推荐:

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

模块注释

推荐:

<!-- 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 -->

语义化

常见标签语义:
标签语义
<p>段落
<hn>标题(h2~h7)
<ul>无序列表
<ol>有序列表
<nav>标记导航,仅对文档中重要的链接群使用
<main>页面主要内容,一个页面只能使用一次。如果是 web 应用,则包围其主要功能
<article>定义外部的内容,其中的内容独立于文档的其余部分
<section>定义文档中的节(section、区段)。比如章节、页眉、页脚或文档中的其他部分。
<aside>定义其所处内容之外的内容。如侧栏、文章的一组链接、广告、友情链接、相关产品列表
<header>页眉通常包括网站标志、主导航、全站链接以及搜索框
<footer>页脚,只有当父级是 body 时,才是整个页面的页脚
<figure>规定独立的流内容(图像、图表、照片、代码等等)(默认有 40px 左右 margin)

到此,相信大家对“HTML规范有哪些”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

推荐阅读:
  1. 规范自己的html
  2. CommonJS规范有哪些

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

html

上一篇:MySQL中如何解决server has gone away问题

下一篇:零基础html5网站开发学习的方法有哪些

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》