先安装node,然后安装http-server
- // 安装http-server
- $ npm install -g http-server
启动本地服务
- // 启动http-server
- $ http-server -p 8888
即可访问:http://localhost:8888/
·让人更容易读懂,增加代码可读性
·让搜索引擎更容易读懂,SEO(Search Engine Optimization,搜索引擎优化)
- <h1>标题h1>
- <div>
- <p>文字p>
- <ul>
- <li>列表li>
- <li>列表li>
- ul>
- div>
·块状元素,display:block/table; 独占一行,有 div、h1、h2、table、ul、ol、p等
·内联元素,display:inline/inline-block; 在一行往后挤,有 span、img、input、button等
- 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>盒模型的宽度title>
- <style type="text/css">
- #div1 {
- width: 100px;
- padding: 10px;
- border: 1px solid red;
- margin: 10px;
- }
- #div2 {
- width: 100px;
- padding: 10px;
- border: 1px solid red;
- margin: 10px;
- box-sizing: border-box;
- }
- style>
- head>
- <body>
- <div id="div1">
- this is div1
- div>
- <div id="div2">
- this is div2
- div>
- body>
- <script>
- // offsetWidth = 内容宽度 + 内边距 + 边框,无外边距
- console.log(document.getElementById('div1').offsetWidth); // 122
- // 设了box-sizing: border-box 后,offsetWidth = width = 100px,内容宽度为78
- console.log(document.getElementById('div2').offsetWidth); // 100
- script>
- html>
·相邻元素的 margin-top 和 margin-bottom 会发生重叠
·空白内容的
也会重叠- html>
- <html>
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <title>margin 纵向重叠title>
-
-
- <style type="text/css">
- p {
- font-size: 16px;
- line-height: 1;
- margin-top: 10px;
- margin-bottom: 15px;
- }
- style>
- head>
- <body>
- <p>AAAp>
- <p>p>
- <p>p>
- <p>p>
- <p>BBBp>
- body>
- html>
·margin-top 和 margin-left 负值,元素向上、向左移动
·margin-right 负值,右侧元素左移,自身不受影响
·margin-bottom 负值,下方元素上移,自身不受影响
·Bloc