开发网页基础-base.css(重置CSS样式)

很多人认为不用重置样式,对应着写不会出现什么问题,但是开发的时候避免因为样式的开发出现BUG,事先还是要重置样式!

  • 问题出现情况:
  • 往往是开发容易,维护难。有没有想过代码的维护性;如今前端井喷式的发展,加上很多不是学前端的来开发网页,当你接手这些开发的代码,重写的时候满脸问号
  • 改这边好不好呢,改了会不会其他页面会不会以前变化
  • 所以组件化的开发还是需要在开发的时候具备

1. 什么是base.css?

  • base又名通用原子类(重置浏览器带来的样式影响)
  • 在写css文件时,一些常用的属性我们完全可以把它单独提出来,提高复用性,能增加开发效率
/*css reset*/


/*重置清除样式*/

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;
}

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;
}

li {
    list-style: none;
}

a,
img {
    border: none;
    margin: 0;
}

body {
    height: auto;
    font-family: "微软雅黑", Helvetica Neue, Helvetica, Arial, sans-serif !important;
}

input,
select,
textarea {
    font-family: "微软雅黑", Helvetica Neue, Helvetica, Arial, sans-serif;
    outline: none;
    vertical-align: middle;
}

i,
b,
strong {
    font-weight: normal;
    font-style: normal;
}

a {
    text-decoration: none;
    cursor: pointer;
/*手机端点中去除选中颜色*/
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    tap-highlight-color: rgba(0, 0, 0, 0);
}

a:link,
a:hover,
a:visited,
a:active,
a:focus {
    text-decoration: none;
    outline: none;
}

*html {
    background-image: url(about:blank);
    background-attachment: fixed;
}


/*兼容IE6定位抖动的*/


/*字体排版*/

.f12 {
    font-size: 12px;
}

.f13 {
    font-size: 13px;
}

.f14 {
    font-size: 14px;
}

.f16 {
    font-size: 16px;
}

.f18 {
    font-size: 18px;
}

.f20 {
    font-size: 20px;
}

.fb {
    font-weight: bold;
}

.fn {
    font-weight: normal;
}

.t2 {
    text-indent: 2em;
}

.lh150 {
    line-height: 150%;
}

.lh180 {
    line-height: 180%;
}

.lh200 {
    line-height: 200%;
}

.unl {
    text-decoration: underline;
}

.no_unl {
    text-decoration: none;
}


/*定位*/

.tl {
    text-align: left;
}

.tr {
    text-align: right;
}

.tc {
    text-align: center;
}

.bc {
    margin-left: auto;
    margin-right: auto;
}

.fl {
    float: left;
    display: inline;
}

.fr {
    float: right;
    display: inline;
}

html {
    width: 100%;
    -webkit-text-size-adjust: none;
    -moz-text-size-adjust: none;
    -ms-text-size-adjust: none;
    -o-text-size-adjust: none;
    text-size-adjust: none;
}


/*盒子样式*/
/*请了解清楚这行盒子模型的理解再使用
*
*/
*,
*:after,
*:before {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    -ms-box-sizing: border-box;
    -o-box-sizing: border-box;
    box-sizing: border-box;
}
/*
*
*/
.cb {
    clear: both;
}

.cl {
    clear: left;
}

.cr {
    clear: right;
}

.clearfix:after {
    content: ".";
    display: block;
    height: 0;
    clear: both;
    visibility: hidden;
}

.clearfix {
    display: inline-block;
}

*html.clearfix {
    height: 1%;
}

.Clearfix {
    display: block;
}

.vm {
    vertical-align: middle;
}

.pr {
    position: relative;
}

.pa {
    position: absolute;
}

.abs-right {
    position: absolute;
    right: 0;
}

.zoom {
    *zoom: 1;
}

.hidden {
    visibility: hidden;
}

.none {
    display: none;
}


/*长度宽度*/

.w10 {
    width: 10px;
}

.w20 {
    width: 20px;
}

.w40 {
    width: 40px;
}

.w60 {
    width: 60px;
}

.w80 {
    width: 80px;
}

.w100 {
    width: 100px;
}

.w200 {
    width: 200px;
}

.w260 {
    width: 260px;
}

.w400 {
    width: 400px;
}

.w600 {
    width: 600px;
}

.w800 {
    width: 800px;
}

.w {
    width: 100%;
}


小结

  • 有些人觉得不用重置样式,我其实是这样理解的,虽然有些样式不一定会用到,会浪费一些资源,但是有时候开发时间很急的时候,不一定想的起来,这样省时间。
  • 上面的样式是我日常用的,如果有补充我会重新发布文章
  • 有些样式不经常用的我已经删除了
  • 如果你们用不习惯可以更改命名,变成自己的样式
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 14,692评论 1 92
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,054评论 25 709
  • 转载请声明 原文链接地址 关注公众号获取更多资讯 第一部分 HTML 第一章 职业规划和前景 职业方向规划定位...
    前端进阶之旅阅读 16,736评论 32 459
  • (这是拖欠了Elle许久的读后感,写得很像随笔,有点仓促多多包涵。这是我内心的一些感触和想法,想说的还有很多。如果...
    心晴Caitlin阅读 4,542评论 0 0
  • 今天在村卫生所呆了一天,看着来来往往的老人,打针输液。家里的孩子们你来我往的替班陪伴照顾,到了这个年龄,深深的感到...
    Una笑笑阅读 1,270评论 0 1

友情链接更多精彩内容