html中的大部分的标签都有一些糟糕的样式,有的是标签天然自带的,有的是浏览器默认设置的,我们在写网页时,这些默认的样式就会时不时的跳出来捣一下乱,搞得我们很是无奈。所以成手在写css样式时,一般都会在开头写一段初始化程序,来去掉这些默认样式,比如最简单的方法就是使用*{margin:0;padding:0;}。但是通常我们很少使用这种方法,因为通配符*的效率极低。那我们应该使用哪种方法呢,下面博主就来为大家介绍一些常用的方法。

一、浏览器默认样式总结

  在介绍初始化程序之前,我们先了解一下都有那些标签被设置了哪些默认样式,只有了解清楚了这些,我们才能更好的对标签样式初始化。

(一)、标签自带样式

//块级元素
html, body, div,ol, p, ul, h1, h2,h3,h4,h5, h6,
address,blockquote, form,
dd,dl, dt, fieldset, frame, frameset,noframes,center, dir, hr, menu, pre
{ display: block } //列表元素类
li{ display:list-item }
ol{list-style-type: decimal }
ol ul, ul ol,ul ul, ol ol { margin-top: 0; margin-bottom: 0 }
ol, ul{ margin-left: 40px } //预格式文本类
i, cite, em,var, address{ font-style: italic }
big{ font-size:1.17em }
small, sub, sup{ font-size: .83em }
sub{ vertical-align:sub }
sup{ vertical-align:super }
s, strike, del{ text-decoration: line-through }
u, ins{ text-decoration:underline } //标题类
h1{ font-size:2em; margin: .67em 0 }
h2{ font-size:1.5em; margin: .75em 0 }
h3{ font-size:1.17em; margin: .83em 0 }
h4, p,blockquote, ul,fieldset, form,ol, dl, dir,menu { margin: 1.12em 0}
h5 { font-size:.83em; margin: 1.5em 0 }
h6{ font-size:.75em; margin: 1.67em 0 }
h1, h2, h3, h4,h5, h6, b,strong { font-weight: bolder } //伪类
br:before{ content: ”\A” }
:before, :after{ white-space: pre-line }
:link, :visited { text-decoration: underline }
:focus{ outline: thin dotted invert } //表格类
table{ display: table }
tr{ display:table-row }
thead{ display:table-header-group }
tbody{ display:table-row-group }
tfoot{ display:table-footer-group }
col{ display:table-column }
colgroup{ display:table-column-group }
td, th{ display: table-cell;}
caption{ display: table-caption }
th{font-weight: bolder; text-align: center }
caption{ text-align: center }
table{ border-spacing: 2px;}
thead, tbody,tfoot { vertical-align:middle }
td, th { vertical-align:inherit } //其它元素
head{ display: none }
body{ margin: 8px;line-height: 1.12 }
button, textarea,input, object,select { display:inline-block;}
blockquote{ margin-left: 40px;margin-right: 40px }
pre, tt, code,kbd, samp { font-family: monospace }
pre{ white-space: pre}
hr{ border: 1px inset }
center{ text-align: center }
abbr, acronym{ font-variant: small-caps; letter-spacing:0.1em } BDO[DIR="ltr"] { direction: ltr; unicode-bidi:bidi-override }
BDO[DIR="rtl"] { direction: rtl; unicode-bidi:bidi-override }
/*定义BDO元素当其属性为DIR="ltr/rtl"时的默认文本读写显示顺序*/
*[DIR="ltr"]{ direction: ltr;unicode-bidi: embed }
*[DIR="rtl"] { direction: rtl;unicode-bidi: embed }
/*定义任何元素当其属性为DIR="rtl/rtl"时的默认文本读写显示顺序*/
@media print {
h1{page-break-before: always }
h1, h2, h3,h4, h5, h6 { page-break-after: avoid }
ul, ol, dl{ page-break-before: avoid }
} /*定义标题和列表默认的打印样式*/

(二)、浏览默认样式类

  不同的浏览器默认的样式可能不尽相同,所以开发时的第一件事可能就是如何把它们统一。如果没对CSS初始化往往会出现浏览器之间的页面差异。

  1.页边距

    IE默认为10px,通过body的margin属性设置
    FF默认为8px,通过body的padding属性设置

  2.段间距

    IE默认为19px,通过p的margin-top属性设置
    FF默认为1.12em,通过p的margin-bottom属性设

  3.标题样式

    h1~h6默认加粗显示:font-weight:bold;
    默认大小请参上表
    还有是这样的写的

h1 {font-size:xx-large;}
h2 {font-size:x-large;}
h3 {font-size:large;}
h4 {font-size:medium;}
h5 {font-size:small;}
h6 {font-size:x-small;}

  4.列表样式
    IE默认为40px,通过ul、ol的margin属性设置
    FF默认为40px,通过ul、ol的padding属性设置
    dl无缩进,但起内部的说明元素dd默认缩进40px,而名称元素dt没有缩进。

  5.元素居中

    IE默认为text-align:center;

    FF默认为margin-left:auto;margin-right:auto;

  6.超链接<a>样式

    a 样式默认带有下划线,显示颜色为蓝色,被访问过的超链接变紫色

  7.鼠标样式

    IE默认为cursor:hand;

    FF默认为cursor:pointer;该声明在IE中也有效

  8.图片链接样式
    IE默认为紫色2px的边框线
    FF默认为蓝色2px的边框线  

二、css初始化程序

  博主总结了一些初始化的代码,博友们可以参考一下,具体使用时可以适当地删减一些。

@charset "UTF-8";
/*css 初始化 */
html, body, ul, li, ol, dl, dd, dt, p, h1, h2, h3, h4, h5, h6, form, fieldset, legend, img {
margin: 0;
padding: 0;
} fieldset, img, input, button {
border: none;
padding: 0;
margin: 0;
outline-style: none;
} ul, ol {
list-style: none;
} input {
padding-top: 0;
padding-bottom: 0;
font-family: "SimSun", "宋体";
} select, input {
vertical-align: middle;
} select, input, textarea {
font-size: 12px;
margin: 0;
}
textarea {
resize: none;
} /*防止拖动*/
img {
border: 0;
vertical-align: middle;
} /* 去掉图片低测默认的3像素空白缝隙*/
table {
border-collapse: collapse;
} body {
font: 12px/150% Arial, Verdana, "\5b8b\4f53";
color: #666;
background: #fff
}
h1, h2, h3, h4, h5, h6 {
text-decoration: none;
font-weight: normal;
font-size: 100%;
} s, i, em {
font-style: normal;
text-decoration: none;
}

浏览器默认标签样式总结及css初始化程序的更多相关文章

  1. 浏览器默认标签样式总结及css初始化程序(转)

    浏览器默认标签样式总结及css初始化程序   html中的大部分的标签都有一些糟糕的样式,有的是标签天然自带的,有的是浏览器默认设置的,我们在写网页时,这些默认的样式就会时不时的跳出来捣一下乱,搞得我 ...

  2. Chrome 浏览器默认样式覆盖自己 CSS 样式的解决

    检查 HTML 源代码,DOCTYPE 的声明是否写正确. HTML5 的 DOCTYPE 声明规范: <!DOCTYPE html> 参考链接: css - User agent sty ...

  3. 清除浏览器默认样式的reset.css(转载于reset.css的官方)

    /* http://meyerweb.com/eric/tools/css/reset/ v2.0-modified | 20110126 License: none (public domain) ...

  4. Web前端浏览器默认样式重置(CSS Tools: Reset CSS)

    /* http://meyerweb.com/eric/tools/css/reset/ v2.0 | 20110126 License: none (public domain) */ html, ...

  5. CSS初始化设置

    在网页开发时,由于浏览器默认加载的css样式使得页面显示的样式出现一些意想不到的意外样式,所以首先要进行css的初始化设置. 此外一些常用的样式,比如浮动等也可以放到初始化中备用.

  6. css知多少(4)——解读浏览器默认样式

    上一节<css知多少(3)——样式来源与层叠规则>介绍了样式的五种来源,咱们再通过一张图回顾一下. 对于上面的三层,咱们大概都比较熟悉了.下面的两层中,用户自定义样式一般也就是改一改字号大 ...

  7. css知多少(4)——解读浏览器默认样式(转)

    css知多少(4)——解读浏览器默认样式   上一节<css知多少(3)——样式来源与层叠规则>介绍了样式的五种来源,咱们再通过一张图回顾一下. 对于上面的三层,咱们大概都比较熟悉了.下面 ...

  8. css 框架——base.css,作用是重设浏览器默认样式和提供通用原子类。自己留存

    今天发下我自己的 css 框架——base.css,作用是重设浏览器默认样式和提供通用原子类. @charset "utf-8"; /*! * @名称:base.css * @功能 ...

  9. css清除浏览器默认样式

    css清除浏览器默认样式(代替 *{}) 将代码放入 css 文件,使用 link 引入. /* v2.0 | 20110126 http://meyerweb.com/eric/tools/css/ ...

随机推荐

  1. (转载)C #开源框架

    Json.NET http://json.codeplex.com/ Json.Net 是一个读写Json效率比较高的.Net框架.Json.Net 使得在.Net环境下使用Json更加简单.通过Li ...

  2. git入门篇-----本地操作

    一 ,git的简介 1 ,git的历史 概念性的知识,大家百度一下,就会出现好多优秀的文章供参考,这里我就不多说了. 如果不是当年BitMover公司威胁Linux社区,可能现在我们就没有免费而超级好 ...

  3. ARM NEON 64bit 查找表替换

    没啥效果,如果表的长度在 64个uint8_t之类,应该可以提高查表速度,否则还是C来的快 #ifdef HAVE_NEON_AARCH64 void table_lookup_AArch64_neo ...

  4. ImportError: no module named win32api

    ImportError: no module named win32api 安装win32包就好了 pip install pypiwin32

  5. 测试CPU核心个数

    //测试CPU核心个数 #if !defined (_WIN32) && !defined (_WIN64) #define LINUX #include <unistd.h&g ...

  6. mvc购物车项目

    第一个mvc项目--购物车. 1.购物车需求 a.用户可以登录 b.用户可以购买商品 c.用户可以对购物车的商品进行修改和删除 d.用户可以下订单 e.系统可以发送电子邮件给用户 uml图 2.界面设 ...

  7. mybatis学习(四)

    创建mybatis工程 工程目录: 具体步骤: 1.创建sqlMapConfig.xml文件,配置mybatis的运行环境,事物,数据源,加载mapper映射文件等. 2.创建po类(查询或者返回的属 ...

  8. php:如何使用PHP排序, key为字母+数字的数组(多维数组)

    你还在为如何使用PHP排序字母+数字的数组而烦恼吗? 今天有个小伙伴在群里问:如何将一个key为字母+数字的数组按升序排序呢? 举个例子: $test = [ 'n1' => 22423, 'n ...

  9. 利用perlin noise 生成 wood texture

    %%% Perlin Noise %%% Wood_texture clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image P ...

  10. C语言小程序(七)、石头剪刀布

    本来挺简单的一个程序,但突然想把<Friends>给糅合进去,就多花了一些心思,这是我写过最有趣的程序了. #include <stdio.h> #include <st ...