css reset

本文深入解析CSS样式设置,包括盒模型、布局、字体大小及颜色等核心属性,旨在帮助前端开发者掌握网页样式设计的关键技巧。
* {
  -webkit-box-sizing: border-box;
     -moz-box-sizing: border-box;
          box-sizing: border-box;
}
*:before,
*:after {
  -webkit-box-sizing: border-box;
     -moz-box-sizing: border-box;
          box-sizing: border-box;
}
body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, code, form, fieldset, legend, input, button, textarea, p, blockquote, th, td {
    margin: 0;
    padding: 0;
}
body {
    background: #fff;
    color: #555;
    font-size: 14px;
    font-family: "Arial", "Microsoft YaHei", "黑体", "宋体", sans-serif;
}
td, th, caption {
    font-size: 14px;
}
h1, h2, h3, h4, h5, h6 {
    font-weight: normal;
    font-size: 100%;
}
address, caption, cite, code, dfn, em, strong, th, var {
    font-style: normal;
    font-weight: normal;
}
a {
    color: #555;
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}
img {
    border: none;
    vertical-align: middle;
}
ol, ul, li {
    list-style: none;
}
input, textarea, select, button {
    font: 14px "Arial", "Microsoft YaHei", "黑体", "宋体", sans-serif;
}
table {
    border-collapse: collapse;
}
html {
    overflow-y: scroll;
}
.clearfix:before,
.clearfix:after {
    content: " ";
    display: block;
    height: 0;
    clear: both;
    visibility: hidden;
}
.clearfix {
    *zoom: 1;
}

/*公共类*/
.fl {
    float: left
}
.fr {
    float: right
}
.al {
    text-align: left
}
.ac {
    text-align: center
}
.ar {
    text-align: right
}
.hide {
    display: none
}
### CSS Reset 介绍 CSS Reset 即重置 CSS,也就是重置默认样式。不同浏览器对 HTML 元素有不同的默认样式规则,Reset 通过覆盖这些默认值,确保在所有浏览器中起点一致,避免在 CSS 中重复定义元素的默认样式,让开发者可以从一个统一的基础开始设计页面样式 [^1][^2]。 以前常用 `*{margin:0;padding:0}` 来进行样式重置,但这种方式格式化太严重,逐渐被废弃。国内大型门户如 QQ、淘宝等在进行 CSS Reset 时均有 YUI 的影子,业内使用较多的还有 Erik Meyer’s CSS Reset [^1]。 ### CSS Reset 使用 以下为几种常见的使用方式: #### 手动编写简单的 CSS Reset 可以编写一个简单的 CSS 文件,覆盖常见元素的默认样式。例如: ```css html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, 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, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video { margin: 0; padding: 0; border: 0; font-size: 100%; font: inherit; vertical-align: baseline; } article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section { display: block; } body { line-height: 1; } ol, ul { list-style: none; } blockquote, q { quotes: none; } blockquote:before, blockquote:after, q:before, q:after { content: ''; content: none; } table { border-collapse: collapse; border-spacing: 0; } ``` 将上述代码保存为 `reset.css` 文件,然后在 HTML 文件或前端框架的入口文件中引入: ```html <link rel="stylesheet" href="reset.css"> ``` 在 UniApp 开发中,可以在 `App.vue` 中引入: ```vue <style> @import './reset.css'; /* 其他样式 */ </style> ``` #### 使用第三方 CSS Reset 库 - **normalize.css**:更温和,会保留一些有用的默认样式。可以通过 npm 安装: ```bash npm install normalize.css ``` 安装完成后,在项目入口文件中引入: ```javascript // 在 JavaScript 入口文件中引入 import 'normalize.css'; ``` 在 UniApp 的 `App.vue` 中引入: ```vue <style> @import 'normalize.css'; /* 其他样式 */ </style> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值