本文主要获取网上normalize.css的v8.0.0版本,记录自己对设置样式的理解
可以在github上下载normalize.css文件:https://github.com/necolas/normalize.css/releases
1、-webkit-text-size-adjust属性
该属性最先是由 iOS 1.0 引入的,所以本来就是解决移动设备上的问题而出现的。通常 iPhone(iOS4)横屏时,「-webkit-text-size- adjust」 的值约为140%。
原本webkit桌面版浏览器支持-webkit-text-size-adjust,但是从chrome27之后桌面版开始取消这个属性。因为这个属性会网页缩放的时候没有办法设置大小不能改变,可用性大大降低,特别是对于有视觉障碍的用户。所以如果想取消字号变大,正确的用法应该是:「-webkit-text-size-adjust:100%;」或者「-webkit-text-size-adjust:none;」。
详细可查看网页字体缩放样式-webkit-text-size-adjust的用法详解。
2、长度单位改为em
便于自适应布局。元素font-size单位设置为em,能根据父元素font-size来设置;元素其他属性长度单位设置为em,能根据自身的font-size值设置。
3、hr的修改
不明白原因。待日后查明。
先附上hr的兼容性问题资料关于hr标记在各浏览器中的问题说明。
4、line-height
我们来分析下sup,sub的line-height设置为0的原因。
行框是由该行的所有行内元素的内联框决定的。
行框的上边界由最高的内联框决定,下边界由最低的内联框决定。因此sup、sub会影响到所在行的行高。
line box,inline box及vertical-align分析
深入理解line-height
Firefox中,按钮可以通过::-moz-focus-inner获取到按钮content内容所在区域。::-moz-focus-inner伪元素主要针对按钮类型的元素,包括button类型, reset类型以及submit类型。如果给这个伪类设置边框颜色,按钮会一直保留颜色,而不仅仅是:focus状态的时候。
::-moz-focus-inner可以解决:1)通过行高居中按钮文字时,发现文字偏下 2)点击按钮的时候按钮出现虚线框。
::-moz-focus-inner伪类可以设置按钮虚线框的padding、padding-block-start、padding-block-end、border等值。border:none用于去除点击按钮时按钮中心出现的虚线框。
padding可以设置按钮内部虚线框的内边框。虚线框的内容和button的内容区域是一样的,设置padding值后,虚线框就会往外部扩散,逐渐变大。
对于文本流是水平方向从左到右的html来说:
6、:-moz-focusring
在鼠标选中按钮的时候会触发这个伪类。但是我在Firefox57版本上尝试没有作用。
7、::-webkit-file-upload-button
按钮前面的图标
/*! normalize.css v8.0.0 | MIT License | github.com/necolas/normalize.css */
/* Document
========================================================================== */
/**
* 1. Correct the line height in all browsers.
* 2. Prevent adjustments of font size after orientation changes in iOS.
*/
html {
line-height: 1.15; /* 1 */
-webkit-text-size-adjust: 100%; /* 2 */
}
/* Sections
========================================================================== */
/**
* Remove the margin in all browsers.
*/
body {
margin: 0;
}
/**
* Correct the font size and margin on `h1` elements within `section` and
* `article` contexts in Chrome, Firefox, and Safari.
*/
h1 {
font-size: 2em;
margin: 0.67em 0;
}
/* Grouping content
========================================================================== */
/**
* 1. Add the correct box sizing in Firefox.
* 2. Show the overflow in Edge and IE.
*/
hr {
box-sizing: content-box; /* 1 */
height: 0; /* 1 */
overflow: visible; /* 2 */
}
/**
* 1. Correct the inheritance and scaling of font size in all browsers.
* 2. Correct the odd `em` font sizing in all browsers.
*/
pre {
font-family: monospace, monospace; /* 1 */ /*这写错了吧,两个字体都一样??*/
font-size: 1em; /* 2 */
}
/* Text-level semantics
========================================================================== */
/**
* Remove the gray background on active links in IE 10.
*/
a {
background-color: transparent; /*测试了下IE1 标签点击的时候本来就没有背景色??*/
}
/**
* 1. Remove the bottom border in Chrome 57-
* 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.
*/
abbr[title] {
border-bottom: none; /* 1 */
text-decoration: underline; /* 2 */
text-decoration: underline dotted; /* 2 */ /*text-decoration-style、text-decoration-color是C33新增的,有些浏览器不支持*/
}
/**
* Add the correct font weight in Chrome, Edge, and Safari.
*/
b,
strong {
font-weight: bolder; /*取值范围100-900。bold是700,bolder是比bold更粗的*/
}
/**
* 1. Correct the inheritance and scaling of font size in all browsers.
* 2. Correct the odd `em` font sizing in all browsers.
*/
code,
kbd,
samp {
font-family: monospace, monospace; /* 1 */
font-size: 1em; /* 2 */
}
/**
* Add the correct font size in all browsers.
*/
small {
font-size: 80%;
}
/**
* Prevent `sub` and `sup` elements from affecting the line height in
* all browsers.
*/
sub,
sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline; /*先改成基线对齐,和其他文本底部是对齐的。后面会再调整*/
}
sub {
bottom: -0.25em;
}
sup {
top: -0.5em;
}
/* Embedded content
========================================================================== */
/**
* Remove the border on images inside links in IE 10.
*/
img {
border-style: none;
}
/* Forms
========================================================================== */
/**
* 1. Change the font styles in all browsers.
* 2. Remove the margin in Firefox and Safari.
*/
button,
input,
optgroup,
select,
textarea {
font-family: inherit; /* 1 */ /*这些元素上会设置属于自己的字体*/
font-size: 100%; /* 1 */
line-height: 1.15; /* 1 */
margin: 0; /* 2 */
}
/**
* Show the overflow in IE.
* 1. Show the overflow in Edge.
*/
button,
input { /* 1 */
overflow: visible; /*IE这两个元素默认溢出隐藏,改为溢出可见*/
}
/**
* Remove the inheritance of text transform in Edge, Firefox, and IE.
* 1. Remove the inheritance of text transform in Firefox.
*/
button,
select { /* 1 */
text-transform: none; /*不转换文本大小写*/
}
/**
* Correct the inability to style clickable types in iOS and Safari.
*/
button,
[type="button"],
[type="reset"],
[type="submit"] {
/*appearance,改变按钮和其他控件的外观,使其类似于原生控件。Safari、Chrome用-webkit-apperance,火狐用-moz-appperance*/
-webkit-apperance: button;
}
/**
* Remove the inner border and padding in Firefox.
*/
/*可能是早期火狐浏览在button等元素上设置padding、border为0,还是有padding、border。要通过::-moz-focus-inner伪元素上设置才能够解决这一问题*/
button::-moz-focus-inner,
[type="button"]::-moz-focus-inner,
[type="reset"]::-moz-focus-inner,
[type="submit"]::-moz-focus-inner {
border-style: none;
padding: 0;
}
/**
* Restore the focus styles unset by the previous rule.
*/
button:-moz-focusring,
[type="button"]:-moz-focusring,
[type="reset"]:-moz-focusring,
[type="submit"]:-moz-focusring {
outline: 1px dotted ButtonText;
}
/**
* Correct the padding in Firefox.
*/
fieldset {
padding: 0.35em 0.75em 0.625em;
}
/**
* 1. Correct the text wrapping in Edge and IE.
* 2. Correct the color inheritance from `fieldset` elements in IE.
* 3. Remove the padding so developers are not caught out when they zero out
* `fieldset` elements in all browsers.
*/
legend {
box-sizing: border-box; /* 1 */
color: inherit; /* 2 */
display: table; /* 1 */
max-width: 100%; /* 1 */
padding: 0; /* 3 */
white-space: normal; /* 1 */
}
/**
* Add the correct vertical alignment in Chrome, Firefox, and Opera.
*/
progress {
vertical-align: baseline;
}
/**
* Remove the default vertical scrollbar in IE 10+.
*/
textarea {
overflow: auto;
}
/**
* 1. Add the correct box sizing in IE 10.
* 2. Remove the padding in IE 10.
*/
[type="checkbox"],
[type="radio"] {
box-sizing: border-box; /* 1 */
padding: 0; /* 2 */
}
/**
* Correct the cursor style of increment and decrement buttons in Chrome.
*/
[type="number"]::-webkit-inner-spin-button,
[type="number"]::-webkit-outer-spin-button {
height: auto;
}
/**
* 1. Correct the odd appearance in Chrome and Safari.
* 2. Correct the outline style in Safari.
*/
[type="search"] {
-webkit-appearance: textfield; /* 1 */
outline-offset: -2px; /* 2 */
}
/**
* Remove the inner padding in Chrome and Safari on macOS.
*/
[type="search"]::-webkit-search-decoration {
-webkit-appearance: none;
}
/**
* 1. Correct the inability to style clickable types in iOS and Safari.
* 2. Change font properties to `inherit` in Safari.
*/
::-webkit-file-upload-button {
-webkit-appearance: button; /* 1 */
font: inherit; /* 2 */
}
/* Interactive
========================================================================== */
/*
* Add the correct display in Edge, IE 10+, and Firefox.
*/
details {
display: block;
}
/*
* Add the correct display in all browsers.(summary是HTML5新增标签,只有 Chrome 以及 Safari 6 支持。用于显示的标题。summary是是块状元素,display默认block)
*/
summary {
display: list-item;
}
/* Misc
========================================================================== */
/**
* Add the correct display in IE 10+.(HTML5新增标签,模板元素,用于嵌入HTML,特性是标签内容隐藏)
*/
template {
display: none;
}
/**
* Add the correct display in IE 10.(hidden 属性是 HTML5 中的新属性。如果有hidden属性,不显示该元素)
*/
[hidden] {
display: none;
}