热门标签 | HotTags
当前位置:  开发笔记 > 前端 > 正文

重置默认样式cssreset-css教程

最近看到一个词叫cssreset。什么叫做cssreset呢?我理解为重置css,也就是重置默认样式。
最近看到一个词叫css reset。什么叫做css reset呢?我理解为重置css,也就是重置默认样式。

我在HTML下的默认样式中讲到,一些标签元素在HTML下有一个默认属性值,我们在写css页面的时候,为了避免在css中重复定义它们,我们需要重置默认样式(css reset)。每个人的用法和写法都不一样。找到一篇关于css reset的调查文章, 可以看看国外使用css reset的比例调查。

html 
{ 
overflow-x:auto; 
overflow-y:scroll; 
} 
body, dl, dt, dd, ul, 
ol, li, pre, form, fieldset, input, p, blockquote, th, td { 
font-weight:400; 
margin:0; 
padding:0; 
} 
h1, h2, h3, h4, h4, h5 { 
margin:0; 
padding:0; 
} 
body { 
background-color:#FFFFFF; 
color:#666666; 
font-family:Helvetica,Arial,sans-serif; 
font-size:12px; 
padding:0 
10px; 
text-align:left; 
} 
select { 
font-size:12px; 
} 
table { 
border-collapse:collapse; 
} 
fieldset, img { 
border:0 
none; 
} 
fieldset { 
margin:0; 
padding:0; 
} 
fieldset p { 
margin:0; 
padding:0 0 0 8px; 
} 
legend { 
display:none; 
} 
address, caption, em, strong, th, i { 
font-style:normal; 
font-weight:400; 
} 
table caption { 
margin-left:-1px; 
} 
hr { 
border-bottom:1px solid #FFFFFF; 
border-top:1px solid #E4E4E4; 
border-width:1px 0; 
clear:both; 
height:2px; 
margin:5px 0; 
overflow:hidden; 
} 
ol, ul { 
list-style-image:none; 
list-style-position:outside; 
list-style-type:none; 
} 
caption, th 
{ 
text-align:left; 
} 
q:before, q:after, blockquote:before, 
blockquote:after { 
content:""; 
}

百度有啊(www.youa.com):(架构基本上是模仿YUI来做的)

body { 
font-family:arial,helvetica,sans-serif; 
font-size:13px; 
font-size-adjust:none; 
font-stretch:normal; 
font-style: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; 
}

在《超越css》一书中建议我们做网站开始重置所有默认样式:

/* Normalizes margin,padding */ 
body,p,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,p,blockquote,th,td 
{ margin:0;padding:0} 
/* Normalizes font-size for headers */ 
h1,h2,h3,h4,h5,h6 { font-size:100%} 
/* Removes list-style from lists */ 
ol,ul { list-style:none } 
/* Normalizes font-size and font-weight to 
normal */ 
address,caption,cite,code,dfn,em,strong,th,var { font-size:normal; 
font-weight:normal } 
/* Removes list-style from lists */ 
table { 
border-collapse:collapse; border-spacing:0 } 
/* Removes border from fieldset 
and img */ 
fieldset,img { border:0 } 
/* Left-aligns text in caption and 
th */ 
caption,th { text-align:left } 
/* Removes quotation marks from q 
*/ 
q:before,q:after { content:''}

那我们实际写代码的时候该怎么来css reset呢?
我个人推荐使用(Eric Meyer和YUI)的 css reset

Eric Meyer's Reset: 
html, body, 
p, span, applet, object, iframe, 
h1, h2, h3, h4, h5, h6, p, blockquote, 
pre, 
a, abbr, acronym, address, big, cite, code, 
del, dfn, em, font, 
img, ins, kbd, q, s, samp, 
small, strike, strong, sub, sup, tt, var, 
b, 
u, i, center, 
dl, dt, dd, ol, ul, li, 
fieldset, form, label, legend, 
table, caption, tbody, tfoot, thead, tr, th, td { 
margin: 0; 
padding: 0; 
border: 0; 
outline: 0; 
font-size: 100%; 
vertical-align: baseline; 
background: transparent; 
} 
body { 
line-height: 1; 
} 
ol, ul { 
list-style: none; 
} 
blockquote, q { 
quotes: none; 
} 
blockquote:before, 
blockquote:after, 
q:before, q:after { 
content: ''; 
content: none; 
} 
/* remember to define focus styles! */ 
:focus { 
outline: 0; 
} 
/* remember to highlight inserts somehow! */ 
ins { 
text-decoration: none; 
} 
del { 
text-decoration: line-through; 
} 
/* tables still need 'cellspacing="0"' in the markup */ 
table { 
border-collapse: collapse; 
border-spacing: 0; 
} 
YUI: 
body,p,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; 
} 
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; 
}

结合他们的css reset写法,再根据自己的实际情况,一定能写出符合自己网站的完美的css reset。

推荐阅读
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • 本文介绍了lua语言中闭包的特性及其在模式匹配、日期处理、编译和模块化等方面的应用。lua中的闭包是严格遵循词法定界的第一类值,函数可以作为变量自由传递,也可以作为参数传递给其他函数。这些特性使得lua语言具有极大的灵活性,为程序开发带来了便利。 ... [详细]
  • 本文介绍了求解gcdexgcd斐蜀定理的迭代法和递归法,并解释了exgcd的概念和应用。exgcd是指对于不完全为0的非负整数a和b,gcd(a,b)表示a和b的最大公约数,必然存在整数对x和y,使得gcd(a,b)=ax+by。此外,本文还给出了相应的代码示例。 ... [详细]
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • 基于layUI的图片上传前预览功能的2种实现方式
    本文介绍了基于layUI的图片上传前预览功能的两种实现方式:一种是使用blob+FileReader,另一种是使用layUI自带的参数。通过选择文件后点击文件名,在页面中间弹窗内预览图片。其中,layUI自带的参数实现了图片预览功能。该功能依赖于layUI的上传模块,并使用了blob和FileReader来读取本地文件并获取图像的base64编码。点击文件名时会执行See()函数。摘要长度为169字。 ... [详细]
  • Java实战之电影在线观看系统的实现
    本文介绍了Java实战之电影在线观看系统的实现过程。首先对项目进行了简述,然后展示了系统的效果图。接着介绍了系统的核心代码,包括后台用户管理控制器、电影管理控制器和前台电影控制器。最后对项目的环境配置和使用的技术进行了说明,包括JSP、Spring、SpringMVC、MyBatis、html、css、JavaScript、JQuery、Ajax、layui和maven等。 ... [详细]
  • 本文介绍了使用Java实现大数乘法的分治算法,包括输入数据的处理、普通大数乘法的结果和Karatsuba大数乘法的结果。通过改变long类型可以适应不同范围的大数乘法计算。 ... [详细]
  • Webpack5内置处理图片资源的配置方法
    本文介绍了在Webpack5中处理图片资源的配置方法。在Webpack4中,我们需要使用file-loader和url-loader来处理图片资源,但是在Webpack5中,这两个Loader的功能已经被内置到Webpack中,我们只需要简单配置即可实现图片资源的处理。本文还介绍了一些常用的配置方法,如匹配不同类型的图片文件、设置输出路径等。通过本文的学习,读者可以快速掌握Webpack5处理图片资源的方法。 ... [详细]
  • 本文介绍了一些好用的搜索引擎的替代品,包括网盘搜索工具、百度网盘搜索引擎等。同时还介绍了一些笑话大全、GIF笑话图片、动态图等资源的搜索引擎。此外,还推荐了一些迅雷快传搜索和360云盘资源搜索的网盘搜索引擎。 ... [详细]
  • Java验证码——kaptcha的使用配置及样式
    本文介绍了如何使用kaptcha库来实现Java验证码的配置和样式设置,包括pom.xml的依赖配置和web.xml中servlet的配置。 ... [详细]
  • 高质量SQL书写的30条建议
    本文提供了30条关于优化SQL的建议,包括避免使用select *,使用具体字段,以及使用limit 1等。这些建议是基于实际开发经验总结出来的,旨在帮助读者优化SQL查询。 ... [详细]
  • 本文介绍了指针的概念以及在函数调用时使用指针作为参数的情况。指针存放的是变量的地址,通过指针可以修改指针所指的变量的值。然而,如果想要修改指针的指向,就需要使用指针的引用。文章还通过一个简单的示例代码解释了指针的引用的使用方法,并思考了在修改指针的指向后,取指针的输出结果。 ... [详细]
  • 在project.properties添加#Projecttarget.targetandroid-19android.library.reference.1..Sliding ... [详细]
  • 猜字母游戏
    猜字母游戏猜字母游戏——设计数据结构猜字母游戏——设计程序结构猜字母游戏——实现字母生成方法猜字母游戏——实现字母检测方法猜字母游戏——实现主方法1猜字母游戏——设计数据结构1.1 ... [详细]
  • 本文介绍了解决IE678伪类不兼容问题的方法,包括少用CSS3和HTML5独有的属性,使用CSS hacker,使用last-child清除浮动、批量添加标签、去掉list item最后一个的border-right等技巧。同时还介绍了使用after清除浮动时加上IE独有属性zoom:1的处理方法。另外,本文还提到可以使用jQuery代替批量添加标签的功能,以及使用负边距和CSS2选择器element+element去掉list item最后一个的border-right的方法。 ... [详细]
author-avatar
囌格菈帥厎
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有