Edge
Chromium
10.30%
Chrome
Blink
66.40%
Safari
Webkit
9.34%
Opera
Blink
2.99%
Firefox
Gecko
7.89%
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> hello, world </body> </html>
| 类别 | 说明 |
|---|---|
| <html> | HTML页面根元素;定义了整个 HTML 文档 |
| <head> | HTML页面头部元素 |
| <body> | HTML页面主体元素;包括脚本标签<script> |
| 类别 | 说明 |
|---|---|
| <article> | 完整的文章结构;通常包括以下结构化标签 |
| <header> | 页眉/头部信息,通常用在<body>;<article>和<section>头部 |
| <nav> | navigation;导航,使用<ul>实现;顶部、侧边、分页导航 |
| <aside> | 侧边栏 |
| <main> | 主要内容;只允许出现1次 |
| <section> | 节元素,类似于<div>,但是HTML5建议应带上标题<header>;如果不需要标题,使用<div>即可 |
| <footer> | 页脚/底部信息,通常位于<body>、<article>底部,包括:版权声明、友情链接、备案信息等 |
| 类别 | 说明 |
|---|---|
| <div> | division;块,用于分隔区域/布局;对搜索引擎来说,div是无语义的,不利于网站的推广和使用 |
| <span> | 行内块 |
| <h1>-<h6> | headline;标题,h1只能出现一次;便于搜索引擎为网页编制索引 |
| <a> | anchor;超链接/导航;单级导航可直接使用;多级导航应配合列表 |
| <img> | image;图像 |
| <p> | paragraph;段落 |
| <ul><ol> | unordered list有序/ordered list无序列表;其子标签只能是列表项<li>,和列表配合使用 |
| <dl> | defined list自定义列表,其子标签只能是<dt>、<dd> |
| <table> | 表格,包括:行<tr>;标题行单元格<th>、普通单元格<td> |
| <form> | 表单,包括:<input>单行文本输入框、单选、多选;<textarea>多行文输入本框;<button>按钮等 |
| <iframe> | inner-frame;内联框架;在当前页面嵌入/显示另外一个页面 |
| 类别 | 说明 |
|---|---|
| <pre> | 定义预格式文本/按照原始代码的排列方式进行显示 |
| <code> | 定义计算机代码 |
| <sup> | 定义上标字 |
| <sub> | 定义下标字 |
| 类别 | 说明 |
|---|---|
| <small> | 小字体标签 |
| <progress> | 动态进度条标签 |
| <meter> | 静态进度条 |
| <figure> | 可以取代<img> |
| 类别 | 说明 |
|---|---|
| class | 类样式属性;一个元素可以指定多个类,以空格分隔 |
| id | ID属性,唯一标识元素 |
| style | 内联样式属性 |
| data- | 数据属性[自定义属性] |
| title | 额外提示信息 |
| alt | 替换属性 |
| contenteditable | 是否可编辑 |
| src | 资源路径属性 |
| href | 超链接地址属性 |
display: inline;
display: inline-block;
display: block;

| 类别 | 说明 |
|---|---|
| width | 元素内容区宽度 |
| height | 元素内容区高度 |
| padding | 元素填充,也称内边距、内填充;padding-top | padding-right | padding-bottom | padding-left |
| border | 元素边框;border-top | border-right | border-bottom | border-left |
| margin | 元素到其它元素之间的距离,也称外边距、外填充;margin-top | margin-right | margin-bottom | margin-left;负边距也有很惊艳的表现 |
元素的实际宽度 = width + padding-left + padding-right + border-left + border-right 元素的实际高度 = height + padding-top + padding-bottom + border-top + border-bottom
.warn {
color: #eb2f06;
font-weight: 600;
}
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="./css/style.css">//外部样式 <style>//内部样式 body { margin: 0; padding: 0; box-sizing: border-box; } .p-txt { color: var(--txt-wran-color);//使用全局变量 opacity: var(--sn);//使用局部变量 } </style> </head> <body> <h1 style="color: #F40;">hello, world</h1>//内联样式 <p class=“p-txt” style="--sn: 0.1;">第1段</p>//内联变量 <p class=“p-txt” style="--sn: 0.3;">第2段</p>//内联变量 </body> </html>
@charset "utf-8";
@import "./style.css";
:root {
--txt-wran-color: #c81623;
--nav-bg-color: #9f103a;
--w-width: 1000px;
}
.active-color {
color: #f40;
}
.color {
color: #000;
}
<div class=" active-color color">CSS的样式顺序</div>
p {
text-indent: 2em;
margin-bottom: 1em;
}
html {
font-size: 62.5%;
}
<div>
<p>Lorem ipsum dolor sit amet.</p>
</div>
p {
font-size: 2em;
}
div {
font-size: 20px;
}
p {
font-size: 2em;
}
| 类别 | 说明 |
|---|---|
| 全局事件 | onclick |
| 窗口事件 | onresize | onload |
| 表单事件 | oninput | onsubmit | onchange |
| 键盘事件 | onkeyup | onkeydown |
| 鼠标事件 | onmouseup | onmousedown | onmouseover | onmouseout | onmouseenter |
| 多媒体事件 | onplay |
<button onclick="fn()">Click me</button>
<script>
function fn() {
console.log('hi,you clicked me');
}
</script>
<button class="btn">Click me</button>
<script>
window.onload = function () {
let btn = document.querySelector('.btn')
btn.addEventListener('click', function () {
console.log('hi,you clicked me');
alert('hi,you clicked me');
})
}
</script>