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

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

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

2020 年更新: 各个框架基本都已经处理了,还有额外的工具单独引用,已经不需要再用,直接去网上搜索即可。

什么是 base.css?

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

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/*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%;
}

小结

有些人觉得不用重置样式,我其实是这样理解的,虽然有些样式不一定会用到,会浪费一些资源,但是有时候开发时间很急的时候,不一定想的起来,这样省时间。 上面的样式是我日常用的,如果有补充我会重新发布文章 有些样式不经常用的我已经删除了 如果你们用不习惯可以更改命名,变成自己的样式

Licensed under CC BY-NC-SA 4.0