![1c8d6171b6990ef3213032194c5c09c8.png](https://img-blog.csdnimg.cn/img_convert/1c8d6171b6990ef3213032194c5c09c8.png)
Bootstrap的重置表现为,去掉本身样式,然后给元素添加其它样式,额外的样式需要通过明确的.class
类来规范。。
重置CSS的原因:
- 重置浏览器默认值,使用
rem
作为尺寸规格单位,代替em
用于指定可缩放的组件的间隔与缝隙。 - 最大化避免使用
margin-top
,防止使用它造成的垂直外排版(边距)混乱所造成之意想不到结果。更重要的是,一个单一方向的margin
是一个简单的构思模型。 - 为了易于跨设备缩放,
block
块元素必须使用rem
作为margin
的单位。 - 保持
font
相关属性最小的声明,尽可能地使用inherit
属性,不影响容器溢出。
重置CSS中选择覆盖和重定义了哪些元素?
1、table元素
原本样式:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>重置样式</title>
<style>
body {
padding-bottom: 1000px;
}
</style>
</head>
<body>
<table>
<tr>
<td>周一</td>
<td>周二</td>
<td>周三</td>
</tr>
</table>
</body>
</html>
![700d28a764f7aa1a30b76dd566111a33.png](https://img-blog.csdnimg.cn/img_convert/700d28a764f7aa1a30b76dd566111a33.png)
使用Bootstrap重置后的样式:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>重置样式</title>
<style>
body {
padding-bottom: 1000px;
}
</style>
</head>
<body>
<table>
<tr>
<td>周一</td>
<td>周二</td>
<td>周三</td>
</tr>
</table>
</body>
</html>
![a730a4090b11ffe32f438fdf7b377c66.png](https://img-blog.csdnimg.cn/img_convert/a730a4090b11ffe32f438fdf7b377c66.png)
加上额外的样式后:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>重置样式</title>
<style>
body {
padding-bottom: 1000px;
}
</style>
</head>
<body>
<table class="table table-bordered">
<tr>
<td>周一</td>
<td>周二</td>
<td>周三</td>
</tr>
</table>
</body>
</html>
![ac913d744a32304c2712486d101a5464.png](https://img-blog.csdnimg.cn/img_convert/ac913d744a32304c2712486d101a5464.png)
2、页面默认元素 html、body
为提供更好的页面展示效果,Bootstrap v4 更新了<html> and<body>
元素的一些属性。
- 全局性地将每一个元素的
box-sizing
属性(包括*:before
、*:after
都设置border-box
-以确保DIV元素自身定义的宽度不会因为border或padding而超过。 <html>
根元素没有声明font-size
属性,但被假定为16px
大小(这是目前Chrome等浏览器默认值),然后在此基础上采用font-size:1rem
的比例应用于<body>
上,使媒体查询能够轻松的实现缩放,最大程序保障用户偏好和易于访问。<body>
元素被赋予一个全局性的font-family
和line-height
,其下面的诸多表单元素也继承此属性,以防止字体大小错位冲突。- 为了安全起见,
<body>
的background-color
的默认值赋为#fff
。
html:
![dcb3f938a94c85b1802c743eaf187539.png](https://img-blog.csdnimg.cn/img_convert/dcb3f938a94c85b1802c743eaf187539.png)
body:
![198ff08e0369e609ae95acfba9bc808b.png](https://img-blog.csdnimg.cn/img_convert/198ff08e0369e609ae95acfba9bc808b.png)
根节点元素还被赋予了很多值:
![4360115d1ec60b79749707097ca275a1.png](https://img-blog.csdnimg.cn/img_convert/4360115d1ec60b79749707097ca275a1.png)
使用方式:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>重置样式</title>
<style>
body {
padding-bottom: 1000px;
}
.testVal {
width: 100px;
height: 100px;
background: var(--blue);
}
</style>
</head>
<body>
<div class="testVal"></div>
</body>
</html>
![1d5fd985b782778d52bcb914b2730924.png](https://img-blog.csdnimg.cn/img_convert/1d5fd985b782778d52bcb914b2730924.png)
3、标题和段落元素
所有标题和段落元素(如说<h1>
以及<p>
都被重置,系统移除它们的上外边距margin-top
定义,标题添加外边距为margin-bottom: .5rem
,段落元素<p>
添加了外边距margin-bottom:1rem
以形成简洁行距。
原本样式:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>重置样式</title>
<style>
body {
padding-bottom: 1000px;
}
</style>
</head>
<body>
<h1>陈学辉</h1>
<h2>陈学辉</h2>
<h3>陈学辉</h3>
<p>陈学辉</p>
</body>
</html>
![a1f3eca462a95b9ea938b2d413868730.png](https://img-blog.csdnimg.cn/img_convert/a1f3eca462a95b9ea938b2d413868730.png)
使用Bootstrap重置后的样式:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>重置样式</title>
<style>
body {
padding-bottom: 1000px;
}
</style>
</head>
<body>
<h1>陈学辉</h1>
<h2>陈学辉</h2>
<h3>陈学辉</h3>
<p>陈学辉</p>
</body>
</html>
![e2a35d66e0ceace7330c1b6b1c0ecd0d.png](https://img-blog.csdnimg.cn/img_convert/e2a35d66e0ceace7330c1b6b1c0ecd0d.png)
4、列表元素
移除所有的列表元素(<ul>
、<ol>
、 and<dl>
)的外边距margin-top
,并设置为margin-bottom: 1rem
,被嵌套的子列表没margin-bottom
值。
- ul:
原本样式:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>重置样式</title>
<style>
body {
padding-bottom: 1000px;
}
</style>
</head>
<body>
<ul>
<li>red</li>
<li>
<ul>
<li>green</li>
</ul>
</li>
</ul>
</body>
</html>
![4f480129d82276008ba0c1ff316b91fb.png](https://img-blog.csdnimg.cn/img_convert/4f480129d82276008ba0c1ff316b91fb.png)
使用Bootstrap重置后的样式:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>重置样式</title>
<style>
body {
padding-bottom: 1000px;
}
</style>
</head>
<body>
<ul>
<li>red</li>
<li>
<ul>
<li>green</li>
</ul>
</li>
</ul>
</body>
</html>
![a850e445bc5ea26bc7fbfcb4c3968826.png](https://img-blog.csdnimg.cn/img_convert/a850e445bc5ea26bc7fbfcb4c3968826.png)
- ol:
原本样式:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>重置样式</title>
<style>
body {
padding-bottom: 1000px;
}
</style>
</head>
<body>
<ol>
<li>red</li>
<li>
<ol>
<li>green</li>
</ol>
</li>
</ol>
</body>
</html>
![b5e4340f7c71c21a41a6e55ed06fbe18.png](https://img-blog.csdnimg.cn/img_convert/b5e4340f7c71c21a41a6e55ed06fbe18.png)
使用Bootstrap重置后的样式:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>重置样式</title>
<style>
body {
padding-bottom: 1000px;
}
</style>
</head>
<body>
<ol>
<li>red</li>
<li>
<ol>
<li>green</li>
</ol>
</li>
</ol>
</body>
</html>
![0fc424dc99cfa84b102737340f7280bc.png](https://img-blog.csdnimg.cn/img_convert/0fc424dc99cfa84b102737340f7280bc.png)
- dl:
原本样式:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>重置样式</title>
<style>
body {
padding-bottom: 1000px;
}
</style>
</head>
<body>
<dl>
<dt>穷</dt>
<dd>穷,汉语常用字,读作qióng或者gōng,最早见于甲骨文,造字本义为身居洞穴,身体被迫弯屈、不自由,后引申为物质上困顿的、不得志的、贫困的,又引申为追究、终结、尽、完等。(基本信息栏参考资料:)</dd>
</dl>
</body>
</html>
![01d35482599611a459449d3255b873e7.png](https://img-blog.csdnimg.cn/img_convert/01d35482599611a459449d3255b873e7.png)
使用Bootstrap重置后的样式:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>重置样式</title>
<style>
body {
padding-bottom: 1000px;
}
</style>
</head>
<body>
<dl>
<dt>穷</dt>
<dd>穷,汉语常用字,读作qióng或者gōng,最早见于甲骨文,造字本义为身居洞穴,身体被迫弯屈、不自由,后引申为物质上困顿的、不得志的、贫困的,又引申为追究、终结、尽、完等。(基本信息栏参考资料:)</dd>
</dl>
</body>
</html>
![811dbf6b36e78b3f9dc4560d9711491e.png](https://img-blog.csdnimg.cn/img_convert/811dbf6b36e78b3f9dc4560d9711491e.png)
5、pre
预先格式化文本元素
pre
标签可定义预格式化的文本。被包围在pre
>标签元素中的文本通常会保留空格和换行符。而文本也会呈现为等宽字体。- bootstrap重置了
pre
元素,移除了它的margin-top
属性并用rem
作为margin-bottom
的单位。
原本样式:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>重置样式</title>
<style>
body {
padding-bottom: 1000px;
}
</style>
</head>
<body>
<pre><html>
<head>
</pre>
</body>
</html>
![837e4418acdc80e335aab7c3b53bf422.png](https://img-blog.csdnimg.cn/img_convert/837e4418acdc80e335aab7c3b53bf422.png)
使用Bootstrap重置后的样式:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>重置样式</title>
<style>
body {
padding-bottom: 1000px;
}
</style>
</head>
<body>
<pre><html>
<head>
</pre>
</body>
</html>
![2fc7182b6936dd2bb55218197c0c9a02.png](https://img-blog.csdnimg.cn/img_convert/2fc7182b6936dd2bb55218197c0c9a02.png)
6、表格元素
微调了表格的样式,样式化了<caption>
,且确保text-align
属性一致。
原本样式:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>重置样式</title>
</head>
<body>
<table>
<caption>课程表</caption>
<tr>
<td>周一</td>
<td>周二</td>
<td>周三</td>
</tr>
</table>
</body>
</html>
![92da17fa96181d1f99429d79ca4ab97e.png](https://img-blog.csdnimg.cn/img_convert/92da17fa96181d1f99429d79ca4ab97e.png)
使用Bootstrap重置后的样式:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>重置样式</title>
</head>
<body>
<table>
<caption>课程表</caption>
<tr>
<td>周一</td>
<td>周二</td>
<td>周三</td>
</tr>
</table>
</body>
</html>
![ee1ac58011133760ce0694d4777d4b37.png](https://img-blog.csdnimg.cn/img_convert/ee1ac58011133760ce0694d4777d4b37.png)
7、Forms表单元素
<fieldset>
去除了边框、内填充、外边距属性,所以它们可以轻松地用作单一的输入框或者输入框组的放入容器中使用。<legend>
和fieldset字段集一样,也已被重新设计过,显示为不同种类的标题。<label>
加上了display: inline-block
属性,从而可以被用户赋予margin
属性进行布局调用。<input>
、<select>
、<textarea>
s、<button>
基本本来都被规范化处理了,同时重置移除了它们的margin
,并且设置了inline-height: inherit
属性。<textarea>
被修改为只能竖直方向上调整大小,因为水平方向上调整大小经常会“破坏”页面布局
原本样式:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>重置样式</title>
</head>
<body>
<form>
<fieldset>
<legend>标题</legend>
</fieldset>
<p>
<label for="">用户名:</label>
<input type="text">
</p>
<p>
<button>敢点么</button>
<select name="" id="">
<option value="">北京</option>
<option value="">上海</option>
<option value="">广州</option>
</select>
</p>
<p>
<textarea name="" id="" cols="30" rows="10"></textarea>
</p>
</form>
</body>
</html>
![81fc50105c4b19af8403cba9f7e1eba2.png](https://img-blog.csdnimg.cn/img_convert/81fc50105c4b19af8403cba9f7e1eba2.png)
使用Bootstrap重置后的样式:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>重置样式</title>
</head>
<body>
<form>
<fieldset>
<legend>标题</legend>
</fieldset>
<p>
<label for="">用户名:</label>
<input type="text">
</p>
<p>
<button>敢点么</button>
<select name="" id="">
<option value="">北京</option>
<option value="">上海</option>
<option value="">广州</option>
</select>
</p>
<p>
<textarea name="" id="" cols="30" rows="10"></textarea>
</p>
</form>
</body>
</html>
![c263c239a4209226ab3f6a832af6c7cf.png](https://img-blog.csdnimg.cn/img_convert/c263c239a4209226ab3f6a832af6c7cf.png)