一、CSS重置样式表

郁子大约 5 分钟约 1364 字笔记CSS

以下内容引用自该博客open in new window

专门用来对浏览器的样式进行重置,有以下三种方式:

(一)全局

适用于学习场景,容易造成后续代码重叠,样式重复设置等问题

* {
  margin: 0;
  padding: 0;
}

(二)reset.css

  • 直接去除了浏览器的默认样式【少用】

CSS reset(css 重置)基本上是不需要的,至少可以说 80% 的 CSS reset 都是没有必要的,反而增加了页面

CSS 的重写,尤其像 *{margin:0;} 的做法更是要不得(反而破坏了很多 UI 的兼容性,比如说单复选框等)。

我不是一概鄙弃 CSS reset,有些常用标签我也是会简单重置一下的,而且会避免 overwrite(样式重写),以保证样式最精简,渲染最高效

1.淘宝天猫

body,
h1,
h2,
h3,
h4,
h5,
h6,
hr,
p,
blockquote,
dl,
dt,
dd,
ul,
ol,
li,
pre,
form,
fieldset,
legend,
button,
input,
textarea,
th,
td {
  margin: 0;
  padding: 0;
}
body,
button,
input,
select,
textarea {
  font:
    12px/1.5 tahoma,
    arial,
    \5b8b\4f53;
}
h1,
h2,
h3,
h4,
h5,
h6 {
  font-size: 100%;
}
address,
cite,
dfn,
em,
var {
  font-style: normal;
}
code,
kbd,
pre,
samp {
  font-family:
    courier new,
    courier,
    monospace;
}
small {
  font-size: 12px;
}
ul,
ol {
  list-style: none;
}
a {
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
sup {
  vertical-align: text-top;
}
sub {
  vertical-align: text-bottom;
}
legend {
  color: #000;
}
et,
img {
  border: 0;
}
button,
input,
select,
textarea {
  font-size: 100%;
}
table {
  border-collapse: collapse;
  border-spacing: 0;
}

2.腾讯

body,
ol,
ul,
h1,
h2,
h3,
h4,
h5,
h6,
p,
th,
td,
dl,
dd,
form,
fieldset,
legend,
input,
textarea,
select {
  margin: 0;
  padding: 0;
}
body {
  font:
    12px "宋体",
    "Arial Narrow",
    HELVETICA;
  background: #fff;
  -webkit-text-size-adjust: 100%;
}
a {
  color: #2d374b;
  text-decoration: none;
}
a:hover {
  color: #cd0200;
  text-decoration: underline;
}
em {
  font-style: normal;
}
li {
  list-style: none;
}
img {
  border: 0;
  vertical-align: middle;
}
table {
  border-collapse: collapse;
  border-spacing: 0;
}
p {
  word-wrap: break-word;
}

3.百度

body {
  font-family: arial, helvetica, sans-serif;
  font-size: 13px;
  font-size-adjust: none;
  font-stretch: normal;
  fontstyle: normal;
  font-variant: normal;
  font-weight: normal;
  line-height: 1.4;
  text-align: center;
}
body,
ul,
ol,
dl,
dd,
h1,
h2,
h3,
h4,
h5,
h6,
p,
form,
fieldset,
legend,
input,
textarea,
select,
button,
th,
td {
  margin: 0;
  padding: 0;
}
h1,
h2,
h3,
h4,
h5,
h6 {
  font-size: 100%;
  font-weight: normal;
}
table {
  font-size: inherit;
}
input,
select {
  font-family: arial, helvetica, clean, sans-serif;
  font-size: 100%;
  font-size-adjust: none;
  font-stretch: normal;
  font-style: normal;
  font-variant: normal;
  font-weight: normal;
  line-height: normal;
}
button {
  overflow: visible;
}
th,
em,
strong,
b,
address,
cite {
  font-style: normal;
  font-weight: normal;
}
li {
  list-style-image: none;
  list-style-position: outside;
  list-style-type: none;
}
img,
fieldset {
  border: 0 none;
}
ins {
  text-decoration: none;
}

4.网易

html {
  overflow-y: scroll;
}
body {
  margin: 0;
  padding: 29px 0 0;
  font:
    12px "\5B8B\4F53",
    sans-serif;
  background: #ffffff;
}
div,
dl,
dt,
dd,
ul,
ol,
li,
h1,
h2,
h3,
h4,
h5,
h6,
pre,
form,
fieldset,
input,
textarea,
blockquote,
p {
  padding: 0;
  margin: 0;
}
table,
td,
tr,
th {
  font-size: 12px;
}
li {
  list-style-type: none;
}
img {
  vertical-align: top;
  border: 0;
}
ol,
ul {
  list-style: none;
}
h1,
h2,
h3,
h4,
h5,
h6 {
  font-size: 12px;
  font-weight: normal;
}
address,
cite,
code,
em,
th {
  font-weight: normal;
  font-style: normal;
}

5.新浪

body,
ul,
ol,
li,
p,
h1,
h2,
h3,
h4,
h5,
h6,
form,
fieldset,
table,
td,
img,
div {
  margin: 0;
  padding: 0;
  border: 0;
}
body {
  background: #fff;
  color: #333;
  font-size: 12px;
  margin-top: 5px;
  font-family: "SimSun", "宋体", "Arial Narrow";
}
ul,
ol {
  list-style-type: none;
}
select,
input,
img,
select {
  vertical-align: middle;
}
a {
  text-decoration: none;
}
a:link {
  color: #009;
}
a:visited {
  color: #800080;
}
a:hover,
a:active,
a:focus {
  color: #c00;
  text-decoration: underline;
}

6.搜狐

/* 全局CSS定义 */
body {
  font-family: "宋体";
  text-align: center;
  margin: 0 auto;
  padding: 0;
  background: #fff;
  font-size: 12px;
  color: #333;
}
body > div {
  text-align: center;
  margin-right: auto;
  margin-left: auto;
}
div,
form,
ul,
ol,
li,
span,
p {
  margin: 0;
  padding: 0;
  border: 0;
}
img,
a img {
  border: 0;
  margin: 0;
  padding: 0;
}
h1,
h2,
h3,
h4,
h5,
h6 {
  margin: 0;
  padding: 0;
  font-size: 12px;
  font-weight: normal;
}
ul,
ol,
li {
  list-style: none;
}
table,
td,
input {
  font-size: 12px;
  padding: 0;
}
/* 默认链接颜色 */
a {
  outline-style: none;
  color: #333;
  text-decoration: none;
}
a:hover {
  color: #c00;
  text-decoration: underline;
}

7.土豆

body,
div,
dl,
dt,
dd,
ul,
ol,
li,
h1,
h2,
h3,
h4,
h5,
h6,
pre,
form,
fieldset,
input,
textarea,
p,
blockquote,
th,
td {
  margin: 0;
  padding: 0;
}
body {
  color: #000;
  background: #fff;
  font-size: 12px;
  line-height: 1.25;
  font-family: tahoma, arial, \5b8b\4f53, sans-serif;
}
th,
td {
  text-align: left;
  vertical-align: top;
}
h1,
h2,
h3,
h4,
h5,
h6 {
  font-size: 1em;
  font-weight: normal;
}
p {
  margin: 0 0 1em 0;
}
blockquote {
  margin: 0 0 1em 0;
}
a {
  color: #14647d;
  text-decoration: none;
  font-family: tahoma, arial, \5b8b\4f53, sans-serif;
  _font-family: arial, sans-serif;
}
a:hover {
  text-decoration: underline;
}
img {
  display: block;
  border: 0;
}
li {
  list-style: none;
}
ol {
  padding: 0 0 0 2em;
}
input,
label,
select,
option,
textarea,
button,
fieldset,
legend {
  font-size: 1em;
  font-family: tahoma, arial, \5b8b\4f53, sans-serif;
  _font-family: Arial, sans-serif;
}
input[type="text"],
textarea {
  -webkit-appearance: none;
  -webkit-border-radius: 0;
  outline: none;
}
input.text {
  color: #444;
  border-color: #9f9f9f #dcdcdc #dcdcdc #9f9f9f;
  border-style: solid;
  border-width: 1px;
  padding: 3px 2px;
  height: 14px;
}
input.radio,
input.checkbox {
  margin-right: 2px;
  vertical-align: -2px;
}
input.radio,
input.checkbox {
  margin-left: -2px;
}
label.radio,
label.checkbox {
  margin-right: 5px;
}
textarea {
  border-color: #9f9f9f #dcdcdc #dcdcdc #9f9f9f;
  border-style: solid;
  border-width: 1px;
  padding: 1px;
  resize: none;
}

8.雅虎

/*
YUI 3.18.1 (build f7e7bcb)
Copyright 2014 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
*/
html {
  color: #000;
  background: #fff;
}
body,
div,
dl,
dt,
dd,
ul,
ol,
li,
h1,
h2,
h3,
h4,
h5,
h6,
pre,
code,
form,
fieldset,
legend,
input,
textarea,
p,
blockquote,
th,
td {
  margin: 0;
  padding: 0;
}
table {
  border-collapse: collapse;
  border-spacing: 0;
}
fieldset,
img {
  border: 0;
}
address,
caption,
cite,
code,
dfn,
em,
strong,
th,
var {
  font-style: normal;
  font-weight: normal;
}
ol,
ul {
  list-style: none;
}
caption,
th {
  text-align: left;
}
h1,
h2,
h3,
h4,
h5,
h6 {
  font-size: 100%;
  font-weight: normal;
}
q:before,
q:after {
  content: "";
}
abbr,
acronym {
  border: 0;
  font-variant: normal;
}
sup {
  vertical-align: text-top;
}
sub {
  vertical-align: text-bottom;
}
input,
textarea,
select {
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  *font-size: 100%;
}
legend {
  color: #000;
}
#yui3-css-stamp.cssreset {
  display: none;
}

(三)normalize.css

Normalize.css 只是一个很小的 CSS 文件,但它在默认的 HTML 元素样式上提供了跨浏览器的高度一致性

相比于传统的 CSS resetNormalize.css 是一种现代的、为 HTML5 准备的优质替代方案

Normalize.css 现在已经被用于 TwitterBootstrapHTML5 BoilerplateGOV.UKRdioCSS Tricks 以及许许多多其他框架、工具和网站上

上次编辑于: