源码解读

关于CSS Reset那二个事(2卡塔 尔(阿拉伯语:قطر‎:Normalize.css 源码解读

2015/08/02 · CSS · CSS Reset, Normalize.css

初藳出处: Alsiso   

关于CSS Reset那些事(3):架构CSS基础库

2015/08/03 · CSS · CSS Reset

原版的书文出处: Alsiso   

/*! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css */

前言

上大器晚成章节牵线了CSS Reset的野史,最终对Normalize.css做了简便的打听,所以从那节最初对源码进行表明翻译与解读,尽恐怕从最根特性的主题素材询问它在帮大家做什么样?

回顾:有关CSS Reset 那多少个事(风流倜傥卡塔 尔(阿拉伯语:قطر‎之 历史蜕变与Normalize.css

前言

上意气风发章节大家对Normalize.css源码进行解析,但是由于其代码过长导致不宜浏览,所以表单Forms,表格Table部分内容放在此章节介绍。本章节会完成所有源代码翻译整理,最终会整理出Normalize-zh.css中文版本并开源至Github供大家交流使用。

回顾:有关CSS Reset 那多少个事(二卡塔 尔(英语:State of Qatar)之 Normalize.css 源码解读

//

Normalize 源码解读

这两天讲到的分模块解读,正是先黏贴意气风发段源码,然后依照官方提供的注释实行翻译收拾,尽大概提供案例解析,然后再度张开重新整建总括,要是你有问号,能够留言一齐调换。

源码地址:https://github.com/necolas/normalize.css/blob/master/normalize.css
源码版本:v3.0.3

Normalize-zh.css 出炉

Normalize-zh.css是根据对Normalize.css的源码分析后,经过学习与整理,将源代码中的英文注释文档翻译为中文版本,方便国内的开发者学习和使用,我深知此版本一定有很多不足,希望能得到大家的理解和支持,同样也很愿意和大家一起完善。

现已将源代码开源至Github

体系地址:

// 1. Set default font family to sans-serif.

html与body 元素

CSS

/** * 1. Set default font family to sans-serif. * 2. Prevent iOS and IE text size adjust after device orientation change, * without disabling user zoom. */ html { font-family: sans-serif; /* 1 */ -ms-text-size-adjust: 100%; /* 2 */ -webkit-text-size-adjust: 100%; /* 2 */ }

1
2
3
4
5
6
7
8
9
10
/**
* 1. Set default font family to sans-serif.
* 2. Prevent iOS and IE text size adjust after device orientation change,
*    without disabling user zoom.
*/
html {
  font-family: sans-serif; /* 1 */
  -ms-text-size-adjust: 100%; /* 2 */
  -webkit-text-size-adjust: 100%; /* 2 */
}
  1. 安装全局的书体为sans-serif,关于中文字体的安装可参谋 Amaze UI
  2. 防守 iOS 横屏字号放大,同不常候保险在PC上 zoom 功用寻常

第三个难点场景是那般,苹果IOS设备调治后会自动调度文字的分寸,遵照苹果的意图是为了进步客商体验,譬喻竖屏状态下是14px,转变为横屏时就形成了20px,把text-size-adjust:100%就不会调节字体大小了。

假使把值设置为'text-size-adjust:none',那么就能招致顾客不可能松手缩短字体了。

CSS

/** * Remove default margin. */ body { margin: 0; }

1
2
3
4
5
6
7
/**
* Remove default margin.
*/
 
body {
  margin: 0;
}
  • 修补浏览器默许边距,统风流倜傥效果

Normalize 源码解读 (2)

上章节对 html与body成分,HTML5成分,链接,语义化文本,内嵌成分,群组元素等源码内容已经做了剖判,这章节继续变成表单Forms,表格Table部分。

源码地址:

源码版本:v3.0.3

// 2. Prevent iOS and IE text size adjust after device orientation change,

HTML5 元素 display definitions

CSS

/** * Correct `block` display not defined for any HTML5 element in IE 8/9. * Correct `block` display not defined for `details` or `summary` in IE 10/11 * and Firefox. * Correct `block` display not defined for `main` in IE 11. */ article, aside, details, figcaption, figure, footer, header, hgroup, main, menu, nav, section, summary { display: block; }

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/**
* Correct `block` display not defined for any HTML5 element in IE 8/9.
* Correct `block` display not defined for `details` or `summary` in IE 10/11
* and Firefox.
* Correct `block` display not defined for `main` in IE 11.
*/
 
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
main,
menu,
nav,
section,
summary {
  display: block;
}
  • 修复 IE 8/9,HTML5新因素不能够正确展现的主题材料,定义为block的元素
  • 修复 IE 10/11,details 和 summary 定义为 block 的元素
  • 修复 IE 11,main定义为 block 的元素

其黄金时代标题或然我们都早就极度理解,当低版本浏览器遭受不识其他成分时,会默许把他们当成内联成分(inline),这里再度定义成为block元素。

CSS

/** * 1. Correct `inline-block` display not defined in IE 8/9. *

  1. Normalize vertical alignment of `progress` in Chrome, Firefox, and Opera. */ audio, canvas, progress, video { display: inline-block; /* 1 */ vertical-align: baseline; /* 2 */ }
1
2
3
4
5
6
7
8
9
10
11
12
/**
* 1. Correct `inline-block` display not defined in IE 8/9.
* 2. Normalize vertical alignment of `progress` in Chrome, Firefox, and Opera.
*/
 
audio,
canvas,
progress,
video {
  display: inline-block; /* 1 */
  vertical-align: baseline; /* 2 */
}
  1. 修补 IE 8/9,HTML5新因素无法正确展现的标题,定义为inline-block元素
  2. 修复Chrome, Firefox, 和Opera的progress要素未有以baseline垂直对齐

progress是HTML5的新标签,能够定义进度条,可是它Chrome, Firefox, 和Opera并从未已baseline垂直对齐。

CSS

/** * Prevent modern browsers from displaying `audio` without controls. * Remove excess height in iOS 5 devices. */ audio:not([controls]) { display: none; height: 0; }

1
2
3
4
5
6
7
8
/**
* Prevent modern browsers from displaying `audio` without controls.
* Remove excess height in iOS 5 devices.
*/
audio:not([controls]) {
  display: none;
  height: 0;
}
  • 对不扶持controls本性的浏览器,audio要素给以隐敝
  • 移除iOS5设备中多余的万丈

在IE8早先的浏览器是不扶植controls属性,这里的点子是一向蒙蔽该因素

CSS

/** * Address `[hidden]` styling not present in IE 8/9/10. * Hide the `template` element in IE 8/9/10/11, Safari, and Firefox <

  1. */ [hidden], template { display: none; }
1
2
3
4
5
6
7
8
9
/**
* Address `[hidden]` styling not present in IE 8/9/10.
* Hide the `template` element in IE 8/9/10/11, Safari, and Firefox < 22.
*/
 
[hidden],
template {
  display: none;
}
  • 修复 IE 7/8/9,Firefox 3 和 Safari 4 中hidden属性不起作用的标题
  • 在 IE,Safari,Firefox 22- 中隐藏template元素

hidden是HTML5的新因素,能够对成分实行掩盖,不过低版本浏览器并不会识别它,这里统生机勃勃做了体制。

template标签用于HTML模板,大家应该都是用过HTML模版开拓页面,这几个标签是依照实际要求增进的,不过模板又无法在分界面上海展览中心示,所以这里统一了体制,宽容旧浏览器。

表单 Forms

CSS

/** * 1. Correct color not being inherited. * Known issue: affects color of disabled elements. * 2. Correct font properties not being inherited. * 3. Address margins set differently in Firefox 4 , Safari, and Chrome. */ button, input, optgroup, select, textarea { color: inherit; /* 1 */ font: inherit; /* 2 */ margin: 0; /* 3 */ }

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/**
* 1. Correct color not being inherited.
*    Known issue: affects color of disabled elements.
* 2. Correct font properties not being inherited.
* 3. Address margins set differently in Firefox 4 , Safari, and Chrome.
*/
 
button,
input,
optgroup,
select,
textarea {
  color: inherit; /* 1 */
  font: inherit; /* 2 */
  margin: 0; /* 3 */
}
  1. 纠正全体浏览器中颜色不继续的标题
  2. 校订全数浏览器中字体不三番两次的标题
  3. 改良 Firefox 3 , Safari5 和 Chrome 中外边距区别的标题

有风度翩翩对浏览器会把form表单中的一些元素 textarea,text,button,select 中的字体和字体颜色默认会设置成用户的字体或者是浏览器的字体,并不会从父元素继承,所以这里重置了这些元素的默认样式。

CSS

/** * Address `overflow` set to `hidden` in IE 8/9/10/11. */ button { overflow: visible; }

1
2
3
4
5
6
7
/**
* Address `overflow` set to `hidden` in IE 8/9/10/11.
*/
 
button {
  overflow: visible;
}
  • 统一 IE 8/9/10/11 overflow属性为visible

在 IE 8/9/10/11里的button默认的overflow是hidden,这里统一为visible

CSS

/** * Address inconsistent `text-transform` inheritance for `button` and `select`. * All other form control elements do not inherit `text-transform` values. * Correct `button` style inheritance in Firefox, IE 8/9/10/11, and Opera. * Correct `select` style inheritance in Firefox. */ button, select { text-transform: none; }

1
2
3
4
5
6
7
8
9
10
11
/**
* Address inconsistent `text-transform` inheritance for `button` and `select`.
* All other form control elements do not inherit `text-transform` values.
* Correct `button` style inheritance in Firefox, IE 8/9/10/11, and Opera.
* Correct `select` style inheritance in Firefox.
*/
 
button,
select {
  text-transform: none;
}
  • 联合各浏览器text-transform不会继承的问题

CSS

/** * 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio` * and `video` controls. * 2. Correct inability to style clickable `input` types in iOS. * 3. Improve usability and consistency of cursor style between image-type * `input` and others. */ button, html input[type="button"], /* 1 */ input[type="reset"], input[type="submit"] { -webkit-appearance: button; /* 2 */ cursor: pointer; /* 3 */ }

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/**
* 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio`
*    and `video` controls.
* 2. Correct inability to style clickable `input` types in iOS.
* 3. Improve usability and consistency of cursor style between image-type
*    `input` and others.
*/
 
button,
html input[type="button"], /* 1 */
input[type="reset"],
input[type="submit"] {
  -webkit-appearance: button; /* 2 */
  cursor: pointer; /* 3 */
}
  1. 避免 Android 4.0.* 中的 WebKit bug ,该bug会毁掉原生的audio和video的控制器
  • 更正 iOS 中无法设置可点击的input的问题
  • 联合其余类其余input的光标样式

此间将可点击的开关,统风流倜傥安装鼠标准样本式为pointer,提高了可用性

CSS

/** * Re-set default cursor for disabled elements. */ button[disabled], html input[disabled] { cursor: default; }

1
2
3
4
5
6
7
8
/**
* Re-set default cursor for disabled elements.
*/
 
button[disabled],
html input[disabled] {
  cursor: default;
}
  • 重新载入参数按键禁止使用时光标样式

CSS

/** * Remove inner padding and border in Firefox 4 . */ button::-moz-focus-inner, input::-moz-focus-inner { border: 0; padding: 0; }

1
2
3
4
5
6
7
8
9
/**
* Remove inner padding and border in Firefox 4 .
*/
 
button::-moz-focus-inner,
input::-moz-focus-inner {
  border: 0;
  padding: 0;
}
  • 移除 Firefox 4 的内边距

CSS

/** * Address Firefox 4 setting `line-height` on `input` using `!important` in * the UA stylesheet. */ input { line-height: normal; }

1
2
3
4
5
6
7
8
/**
* Address Firefox 4 setting `line-height` on `input` using `!important` in
* the UA stylesheet.
*/
 
input {
  line-height: normal;
}
  • 统豆蔻年华设置行高为normal

Firefox浏览器会暗许设置input[type=”button”]的行高为normal !important,这里统一样式

CSS

/** * It's recommended that you don't attempt to style these elements. * Firefox's implementation doesn't respect box-sizing, padding, or width. * * 1. Address box sizing set to `content-box` in IE 8/9/10. * 2. Remove excess padding in IE 8/9/10. */ input[type="checkbox"], input[type="radio"] { box-sizing: border-box; /* 1 */ padding: 0; /* 2 */ }

1
2
3
4
5
6
7
8
9
10
11
12
13
/**
* It's recommended that you don't attempt to style these elements.
* Firefox's implementation doesn't respect box-sizing, padding, or width.
*
* 1. Address box sizing set to `content-box` in IE 8/9/10.
* 2. Remove excess padding in IE 8/9/10.
*/
 
input[type="checkbox"],
input[type="radio"] {
  box-sizing: border-box; /* 1 */
  padding: 0; /* 2 */
}
  1. 改正 IE 8/9 box-sizing 被设置为content-box的问题
  • 移除 IE 8/9 中多余的内边距

CSS

/** * Fix the cursor style for Chrome's increment/decrement buttons. For certain * `font-size` values of the `input`, it causes the cursor style of the * decrement button to change from `default` to `text`. */ input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { height: auto; }

1
2
3
4
5
6
7
8
9
10
/**
* Fix the cursor style for Chrome's increment/decrement buttons. For certain
* `font-size` values of the `input`, it causes the cursor style of the
* decrement button to change from `default` to `text`.
*/
 
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  height: auto;
}
  • 修正 Chrome 中 input [type="number"] 在特定高度和 font-size 时,下面一个箭头光标变成cursor: text 效果

 

CSS

/** * 1. Address `appearance` set to `searchfield` in Safari and Chrome. * 2. Address `box-sizing` set to `border-box` in Safari and Chrome. */ input[type="search"] { -webkit-appearance: textfield; /* 1 */ box-sizing: content-box; /* 2 */ }

1
2
3
4
5
6
7
8
9
/**
* 1. Address `appearance` set to `searchfield` in Safari and Chrome.
* 2. Address `box-sizing` set to `border-box` in Safari and Chrome.
*/
 
input[type="search"] {
  -webkit-appearance: textfield; /* 1 */
  box-sizing: content-box; /* 2 */
}
  1. 修正 Safari 5 和 Chrome 中appearance被设置为searchfield的问题
  • 修正 Safari 5 和 Chrome 中box-sizing被设置为border-box的问题

searchfield是CSS3的属性,它可以让一个div元素看上去像任何元素,但是浏览器支持性并不好,

CSS

/** * Remove inner padding and search cancel button in Safari and Chrome on OS X. * Safari (but not Chrome) clips the cancel button when the search input has * padding (and `textfield` appearance). */ input[type="search"]::-webkit-search-cancel-button, input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; }

1
2
3
4
5
6
7
8
9
10
/**
* Remove inner padding and search cancel button in Safari and Chrome on OS X.
* Safari (but not Chrome) clips the cancel button when the search input has
* padding (and `textfield` appearance).
*/
 
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-decoration {
  -webkit-appearance: none;
}
  • 移除原生暗中同意样式,统生龙活虎search的输入框样式

 

CSS

/** * Define consistent border, margin, and padding. */ fieldset { border: 1px solid #c0c0c0; margin: 0 2px; padding: 0.35em 0.625em 0.75em; }

1
2
3
4
5
6
7
8
9
/**
* Define consistent border, margin, and padding.
*/
 
fieldset {
  border: 1px solid #c0c0c0;
  margin: 0 2px;
  padding: 0.35em 0.625em 0.75em;
}
  • 概念风流倜傥致的边框、外边距和内边距

CSS

/** * 1. Correct `color` not being inherited in IE 8/9/10/11. * 2. Remove padding so people aren't caught out if they zero out fieldsets. */ legend { border: 0; /* 1 */ padding: 0; /* 2 */ }

1
2
3
4
5
6
7
8
9
/**
* 1. Correct `color` not being inherited in IE 8/9/10/11.
* 2. Remove padding so people aren't caught out if they zero out fieldsets.
*/
 
legend {
  border: 0; /* 1 */
  padding: 0; /* 2 */
}
  1. 订正 IE 6-9 中颜色不可能继续的难点
  2. 重新载入参数内边距

CSS

/** * Remove default vertical scrollbar in IE 8/9/10/11. */ textarea { overflow: auto; }

1
2
3
4
5
6
7
/**
* Remove default vertical scrollbar in IE 8/9/10/11.
*/
 
textarea {
  overflow: auto;
}
  • 移除 IE8-11 中暗中认可的垂直滚动条

CSS

/** * Don't inherit the `font-weight` (applied by a rule above). * NOTE: the default cannot safely be changed in Chrome and Safari on OS X. */ optgroup { font-weight: bold; }

1
2
3
4
5
6
7
8
/**
* Don't inherit the `font-weight` (applied by a rule above).
* NOTE: the default cannot safely be changed in Chrome and Safari on OS X.
*/
 
optgroup {
  font-weight: bold;
}
  • 合併设置optgroup元素font-weight始终为bold

//    without disabling user zoom.

链接 Links

CSS

/** * Remove the gray background color from active links in IE 10. */ a { background-color: transparent; }

1
2
3
4
5
6
7
/**
* Remove the gray background color from active links in IE 10.
*/
 
a {
  background-color: transparent;
}
  • 去掉 IE 10 点击链接时的青蓝背景

CSS

/** * Improve readability of focused elements when they are also in an * active/hover state. */ a:active, a:hover { outline: 0; }

1
2
3
4
5
6
7
8
9
/**
* Improve readability of focused elements when they are also in an
* active/hover state.
*/
 
a:active,
a:hover {
  outline: 0;
}
  • 去掉点击时的outline转折点框,同期保险使用键盘可以显得主旨框,那么些操作针对具备浏览器

表格 Tables

CSS

/** * Remove most spacing between table cells. */ table { border-collapse: collapse; border-spacing: 0; } td, th { padding: 0; }

1
2
3
4
5
6
7
8
9
10
11
12
13
/**
* Remove most spacing between table cells.
*/
 
table {
  border-collapse: collapse;
  border-spacing: 0;
}
 
td,
th {
  padding: 0;
}

//

语义化文本标签 Text-level semantics

CSS

/** * Address styling not present in IE 8/9/10/11, Safari, and Chrome. */ abbr[title] { border-bottom: 1px dotted; }

1
2
3
4
5
6
7
/**
* Address styling not present in IE 8/9/10/11, Safari, and Chrome.
*/
 
abbr[title] {
  border-bottom: 1px dotted;
}
  • 修正abbr要素在 Firefox 外别的浏览器未有下划线的标题

语义abbr标签是意味简单称谓或缩写,自己的title性格是总体版,可是此标签在Firefox下默许有上面框,而其余浏览器中绝非,这里统一了体制。

CSS

/** * Address style set to `bolder` in Firefox 4 , Safari, and Chrome. */ b, strong { font-weight: bold; }

1
2
3
4
5
6
7
8
/**
* Address style set to `bolder` in Firefox 4 , Safari, and Chrome.
*/
 
b,
strong {
  font-weight: bold;
}
  • Firefox3 ,Safari4/5 和 Chrome 中集结安装为粗体

Firefox 3 , Safari 和 Chrome 给bstrong安装的习性是bolder,而不是bold,这里统一了体制。

CSS

/** * Address styling not present in Safari and Chrome. */ dfn { font-style: italic; }

1
2
3
4
5
6
7
/**
* Address styling not present in Safari and Chrome.
*/
 
dfn {
  font-style: italic;
}
  • 改善 Safari5 和 Chrome 中并没有样式的标题

dfn 标签可标志这几个对极度术语或短语的概念,在Safari 和Chrome 里不是斜体,在这里边统一了体制。

CSS

/** * Address variable `h1` font-size and margin within `section` and `article` * contexts in Firefox 4 , Safari, and Chrome. */ h1 { font-size: 2em; margin: 0.67em 0; }

1
2
3
4
5
6
7
8
9
/**
* Address variable `h1` font-size and margin within `section` and `article`
* contexts in Firefox 4 , Safari, and Chrome.
*/
 
h1 {
  font-size: 2em;
  margin: 0.67em 0;
}
  • 修复 Firefox 4 ,Safari 5 和 Chrome 中sectionarticle内的h1字体大小

CSS

/** * Address styling not present in IE 8/9. */ mark { background: #ff0; color: #000; }

1
2
3
4
5
6
7
8
/**
* Address styling not present in IE 8/9.
*/
 
mark {
  background: #ff0;
  color: #000;
}
  • 修复 IE 6/9, Safari 5 和 Chrome中样式不显现的主题材料

mark标签用来优秀呈现部分文件,设置后会有三个高亮背景,不过此标签是HTML第55中学的新标签,在低版本浏览器并不识别,所以要求重新初始化样式。

CSS

/** * Address inconsistent and variable font size in all browsers. */ small { font-size: 80%; }

1
2
3
4
5
6
7
/**
* Address inconsistent and variable font size in all browsers.
*/
 
small {
  font-size: 80%;
}
  • 在享有浏览器中集合small的字体大小

small标签在 HTML 4.01 就已经存在,HTML5中拉长了它的意味,表示旁注音讯,不过此标签在豆蔻年华生龙活虎浏览器中表现的字体大小不平等,在这里边做了统生龙活虎

CSS

/** * Prevent `sub` and `sup` affecting `line-height` in all browsers. */ sub, sup { font-size: 75%; line-height: 0; position: relative; vertical-align: baseline; } sup { top: -0.5em; } sub { bottom: -0.25em; }

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/**
* Prevent `sub` and `sup` affecting `line-height` in all browsers.
*/
 
sub,
sup {
  font-size: 75%;
  line-height: 0;
  position: relative;
  vertical-align: baseline;
}
 
sup {
  top: -0.5em;
}
 
sub {
  bottom: -0.25em;
}
  • 防护全数浏览器中的subsup影响行高

supsub七个标签是用来代表上标和下标,据HTML规范中对smallsubsup的尺寸要求都以smaller,不过如上所示normalize.csssmall设的是80%,而subsup却是40%,所认为了保持生龙活虎致,且不影响别的因素的行高,把两个的line-height设为0,然后设置它的垂直以baseline开首,设置topbottom手动设置两个偏移量

总结

由此七个章节对Normalize.css的源码进行了学习,清晰的了解了它的工作原理,作为传统CSS Reset替代者,它当之无愧,为大家提供一套很完整的跨浏览器解决方案。

唯独,你是还是不是会有和作者相通的须求,举例开采三个小站,可能四个PC端的系统时,只怕只须要有的简短的底工模块,比如小编只想要轻便的样式重新初始化,统生机勃勃各浏览器的效能就好,并无需HTML5以至CSS3的有些难题修复。

那就是说下生机勃勃章,大家来介绍,假若制订归于本身的 CSS基本功代码库?

1 赞 1 收藏 评论

图片 1

html{

内嵌成分 Embedded content

CSS

/** * Remove border when inside `a` element in IE 8/9/10. */ img { border: 0; }

1
2
3
4
5
6
7
/**
* Remove border when inside `a` element in IE 8/9/10.
*/
 
img {
  border: 0;
}
  • 去除 IE6-9 和 Firefox 3 中a内部img要素私下认可的边框

在旧版本的浏览器中,图片默许会有三个奇丑无比的浅莲灰边框,那这里开展割除,统同样式。

CSS

/** * Correct overflow not hidden in IE 9/10/11. */ svg:not(:root) { overflow: hidden; }

1
2
3
4
5
6
7
/**
* Correct overflow not hidden in IE 9/10/11.
*/
 
svg:not(:root) {
  overflow: hidden;
}
  • 修复 IE9 中的overflow的奇异表现

font-family:sans-serif;// 1

群组成分 Grouping content

CSS

/** * Address margin not present in IE 8/9 and Safari. */ figure { margin: 1em 40px; }

1
2
3
4
5
6
7
/**
* Address margin not present in IE 8/9 and Safari.
*/
 
figure {
  margin: 1em 40px;
}
  • 修复 IE 8/9、Safari中margin失效

figure 是HTML5的新标签,用做文书档案插图,但它在 IE 8/9 and Safari 中的暗许margin失效,这里做了联合安装。

CSS

/** * Address differences between Firefox and other browsers. */ hr { box-sizing: content-box; height: 0; }

1
2
3
4
5
6
7
8
/**
* Address differences between Firefox and other browsers.
*/
 
hr {
  box-sizing: content-box;
  height: 0;
}
  • 修正 Firefox 和任何浏览器之间的歧异

在 Firefox 中,hr要素的私下认可样式非常多,和其余浏览器首要的差异有两点:
1.设置了height2px;
2.box-sizingborder-box;
此体制对那四个难题举办重新载入参数,举行合并

CSS

/** * Contain overflow in all browsers. */ pre { overflow: auto; }

1
2
3
4
5
6
7
/**
* Contain overflow in all browsers.
*/
 
pre {
  overflow: auto;
}
  • 标签设置滚动条,内容溢出时现身

大比很多浏览器的preoverflow的时候会直接溢出来,这里丰盛overflow:auto让它现身滚动条

CSS

/** * Address odd `em`-unit font size rendering in all browsers. */ code, kbd, pre, samp { font-family: monospace, monospace; font-size: 1em; }

1
2
3
4
5
6
7
8
9
10
11
/**
* Address odd `em`-unit font size rendering in all browsers.
*/
 
code,
kbd,
pre,
samp {
  font-family: monospace, monospace;
  font-size: 1em;
}
  • 用来修复 Safari 5 和 Chrome 中意外的书体设置,统一字体样式,

-ms-text-size-adjust:100%;// 2

总结

此章节大家对Normalize.css中装置的 html与body成分,HTML5成分,链接,语义化文本,内嵌成分,群组成分的源码举行详尽的解读,开采正如其说的生龙活虎律,它不只有帮大家修复了浏览器的私下认可bug,还保留了超多标签的暗中同意值,非常是语义化标签,坚定不移他们存在的意思。

是因为源码部分过长,所以对于源码的剖析会分为两节,下大器晚成节咱们三番五遍来介绍:

表单:表单往往存在重重难题,如周围的种种不接二连三难点,这这里都会得到修复
表格:表格的默许边距和边框真的超级难看,要求修补修复

下后生可畏节会完毕全数模块对normalize.css源码解读,届期会照望后生可畏份normalize-zh.css华语注释的本子上传至Github,供我们参谋运用,敬请期望…

1 赞 收藏 评论

图片 2

-webkit-text-size-adjust:100%;// 2

}

//

// Remove default margin.

//

body{

margin:0;

}

// HTML5 display definitions

//

//

// Correct `block` display not defined for any HTML5 element in IE 8/9.

// Correct `block` display not defined for `details` or `summary` in IE 10/11

// and Firefox.

// Correct `block` display not defined for `main` in IE 11.

//

article,

aside,

details,

figcaption,

figure,

footer,

header,

hgroup,

main,

menu,

nav,

section,

summary{

display:block;

}

//

// 1. Correct `inline-block` display not defined in IE 8/9.

// 2. Normalize vertical alignment of `progress` in Chrome, Firefox, and Opera.

//

audio,

canvas,

progress,

video{

display:inline-block;// 1

vertical-align:baseline;// 2

}

//

// Prevent modern browsers from displaying `audio` without controls.

// Remove excess height in iOS 5 devices.

//

audio:not([controls]) {

display:none;

height:0;

}

//

// Address `[hidden]` styling not present in IE 8/9/10.

// Hide the `template` element in IE 8/9/10/11, Safari, and Firefox < 22.

//

[hidden],

template{

display:none;

}

// Links

//

//

// Remove the gray background color from active links in IE 10.

//

a{

background-color:transparent;

}

//

// Improve readability of focused elements when they are also in an

// active/hover state.

//

a:active,

a:hover{

outline:0;

}

// Text-level semantics

//

//

// Address styling not present in IE 8/9/10/11, Safari, and Chrome.

//

abbr[title] {

border-bottom:1pxdotted;

}

//

// Address style set to `bolder` in Firefox 4 , Safari, and Chrome.

//

b,

strong{

font-weight:bold;

}

//

// Address styling not present in Safari and Chrome.

//

dfn{

font-style:italic;

}

//

// Address variable `h1` font-size and margin within `section` and `article`

// contexts in Firefox 4 , Safari, and Chrome.

//

h1{

font-size:2em;

margin:0.67em0;

}

//

// Address styling not present in IE 8/9.

//

mark{

background:#ff0;

color:#000;

}

//

// Address inconsistent and variable font size in all browsers.

//

small{

font-size:80%;

}

//

// Prevent `sub` and `sup` affecting `line-height` in all browsers.

//

sub,

sup{

font-size:75%;

line-height:0;

position:relative;

vertical-align:baseline;

}

sup{

top:-0.5em;

}

sub{

bottom:-0.25em;

}

// Embedded content

//

//

// Remove border when inside `a` element in IE 8/9/10.

//

img{

border:0;

}

//

// Correct overflow not hidden in IE 9/10/11.

//

svg:not(:root) {

overflow:hidden;

}

// Grouping content

//

//

// Address margin not present in IE 8/9 and Safari.

//

figure{

margin:1em40px;

}

//

// Address differences between Firefox and other browsers.

//

hr{

box-sizing:content-box;

height:0;

}

//

// Contain overflow in all browsers.

//

pre{

overflow:auto;

}

//

// Address odd `em`-unit font size rendering in all browsers.

//

code,

kbd,

pre,

samp{

font-family:monospace,monospace;

font-size:1em;

}

// Forms

//

//

// Known limitation: by default, Chrome and Safari on OS X allow very limited

// styling of `select`, unless a `border` property is set.

//

//

// 1. Correct color not being inherited.

//    Known issue: affects color of disabled elements.

// 2. Correct font properties not being inherited.

// 3. Address margins set differently in Firefox 4 , Safari, and Chrome.

//

button,

input,

optgroup,

select,

textarea{

color:inherit;// 1

font:inherit;// 2

margin:0;// 3

}

//

// Address `overflow` set to `hidden` in IE 8/9/10/11.

//

button{

overflow:visible;

}

//

// Address inconsistent `text-transform` inheritance for `button` and `select`.

// All other form control elements do not inherit `text-transform` values.

// Correct `button` style inheritance in Firefox, IE 8/9/10/11, and Opera.

// Correct `select` style inheritance in Firefox.

//

button,

select{

text-transform:none;

}

//

// 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio`

//    and `video` controls.

// 2. Correct inability to style clickable `input` types in iOS.

// 3. Improve usability and consistency of cursor style between image-type

//    `input` and others.

//

button,

htmlinput[type="button"],// 1

input[type="reset"],

input[type="submit"] {

-webkit-appearance: button;// 2

cursor:pointer;// 3

}

//

// Re-set default cursor for disabled elements.

//

button[disabled],

htmlinput[disabled] {

cursor:default;

}

//

// Remove inner padding and border in Firefox 4 .

//

button::-moz-focus-inner,

input::-moz-focus-inner{

border:0;

padding:0;

}

//

// Address Firefox 4 setting `line-height` on `input` using `!important` in

// the UA stylesheet.

//

input{

line-height:normal;

}

//

// It's recommended that you don't attempt to style these elements.

// Firefox's implementation doesn't respect box-sizing, padding, or width.

//

// 1. Address box sizing set to `content-box` in IE 8/9/10.

// 2. Remove excess padding in IE 8/9/10.

//

input[type="checkbox"],

input[type="radio"] {

box-sizing:border-box;// 1

padding:0;// 2

}

//

// Fix the cursor style for Chrome's increment/decrement buttons. For certain

// `font-size` values of the `input`, it causes the cursor style of the

// decrement button to change from `default` to `text`.

//

input[type="number"]::-webkit-inner-spin-button,

input[type="number"]::-webkit-outer-spin-button{

height:auto;

}

//

// 1. Address `appearance` set to `searchfield` in Safari and Chrome.

// 2. Address `box-sizing` set to `border-box` in Safari and Chrome.

//

input[type="search"] {

-webkit-appearance: textfield;// 1

box-sizing:content-box;//2

}

//

// Remove inner padding and search cancel button in Safari and Chrome on OS X.

// Safari (but not Chrome) clips the cancel button when the search input has

// padding (and `textfield` appearance).

//

input[type="search"]::-webkit-search-cancel-button,

input[type="search"]::-webkit-search-decoration{

-webkit-appearance:none;

}

//

// Define consistent border, margin, and padding.

//

fieldset{

border:1pxsolid#c0c0c0;

margin:02px;

padding:0.35em0.625em0.75em;

}

//

// 1. Correct `color` not being inherited in IE 8/9/10/11.

// 2. Remove padding so people aren't caught out if they zero out fieldsets.

//

legend{

border:0;// 1

padding:0;// 2

}

//

// Remove default vertical scrollbar in IE 8/9/10/11.

//

textarea{

overflow:auto;

}

//

// Don't inherit the `font-weight` (applied by a rule above).

// NOTE: the default cannot safely be changed in Chrome and Safari on OS X.

//

optgroup{

font-weight:bold;

}

// Tables

//

//

// Remove most spacing between table cells.

//

table{

border-collapse:collapse;

border-spacing:0;

}

td,

th{

padding:0;

}

本文由星彩网app下载发布于前端技术,转载请注明出处:源码解读

TAG标签:
Ctrl+D 将本页面保存为书签,全面了解最新资讯,方便快捷。