在自己所做过的项目中还没有使用过颇为流传的 CSS Reset,就发现了下面这篇文章。
其实有时候不需要去技术跟风,只需了解一下便可。那些东西有一定的道理,但不一定适合。就像 CSS Sprite,用的有感觉了,就知道什么地方该用,什么地方不该用。如果每处都用,那就成了滥用了。
个人在平常项目中用到的最多的也就是下面这个
* {
margin: 0px;
padding: 0px;
}
觉得没有必要用 CSS Reset,个人感觉有点画蛇添足了。
IE 6 没特殊要求,基本上是放弃了。因此几个像素的大小并无太大影响,用户毕竟不可能开着2个以上浏览器同时查看一个页面吧。只要看上去精致,该对齐的能对齐了就 OK 了。
When asked recently about using a CSS reset stylesheet, I readily admitted that I don't use them. I don't use them for my blog or for any project that I work on. Admitting such can raise an eyebrow or two. Reset stylesheets are definitely becoming commonplace — as you'd expect with companies like Yahoo and industry leaders like Eric Meyer actively using them.
So, why haven't I jumped on board?
What is a CSS Reset?
In case you've never heard of such a thing, a CSS Reset is designed to set a number of element styles to a specific baseline that creates consistency across various browsers.
In the beginning
When the idea of a reset style was first introduced, it was very basic. It reset the margin and padding for all elements. The problem with that was it caused havoc with elements that didn't want their margins or padding reset (namely, form elements).
* { margin:0; padding:0; }
From there, people worked on adding to and fine-tuning the reset stylesheet to be more flexible and to reset more styles. The Meyer reset is probably the finest culmination of this effort.
Eric Meyer's Reset
Eric Meyer's reset took the concept of resetting margin and padding and took it to a whole new level, stripping styles from a number of elements, forcing you to think about what you wanted and add them back in. List items would no longer have bullets, headings would no longer be bolded, and most elements would be stripped of their margin and padding, along with some other changes.
Working with Nothing
The problem I've had with these resets is that I then find myself declaring much more than I ever needed to just to get browsers back to rendering things the way I want. As it turns out, I'm perfectly happy with how a number of elements render by default. I like lists to have bullets and strong elements to have bolded text.
And I'm okay if the various browsers show things slightly differently.
I'm okay if one browser displays an H1 a few pixels larger or smaller than other browsers. If one browser defaults to circle bullets and another to squares, that's usually not a problem. If it is, then I create a style that addresses that specific issue. I don't reset it back to zero and then set it again to what I really want.
One of the principles I took away from the Web Standards community was the concept that pixel perfect precision across the various rendering engines was impractical and a remnant of the table-based layouts of yesteryear. With CSS and progressive enhancement, it was okay that things might look a little different from one browser to the next because of variations in what they supported.
Building up
With that said, the idea of developing a base CSS file that defines some common styles that I often want from project to project — like turning off margin and padding for form elements — is a good idea.
We're seeing various CSS frameworks crop up such as Blueprint , YUI and 960.gs . Each breaking the system down only to build it back up again. Each starts with a reset, then adds on typography and a grid system.
Each of those still seem like more than I need, even though none are that large in size. Blueprint is the heaviest at around 13KB uncompressed but also includes lots of extras like styles for error messages and a print stylesheet.
Less is more
One of these days I'll put together my own base CSS or maybe I won't. To date, I haven't felt myself being overly repetitive in the styles that I set; and I haven't thought to myself, "oh, the hours I'd save myself if only I had a reset stylesheet."
So, while I have nothing against CSS reset stylesheets, I simply don't use them personally and I think that's okay.
相关推荐
一些开发者开始提倡"No CSS Reset"的理念,认为在某些情况下,仅重置必要的样式或者根据项目需求定制重置可能更为合理。例如,Google的首页就是一个例子,它没有使用任何CSS Reset,而是保持了极简的样式。 CSS ...
一些开发者主张“少即是多”,即根据具体应用场景选择合适的重置策略,甚至完全不使用Reset CSS,如No CSS Reset的理念。他们认为全局的样式重置可能会导致不必要的工作量,尤其是在某些简洁的页面设计中。另一些...
CSS Reset,也称为CSS重置或初始化,是前端开发中的一种常见技术,旨在消除不同浏览器之间的默认样式差异,确保网页在各个浏览器上呈现一致的布局。这个特定的CSS Reset代码是作者在实践中根据前人的经验并结合自己...
【网页架构与CSS Reset】 网页架构是构建网页的基础,它涉及到HTML、CSS和JavaScript等多个方面。在本案例中,我们重点关注CSS的运用,特别是CSS Reset。CSS Reset的主要目的是消除浏览器之间的样式差异,确保元素...
1. **CSS Reset**:在CSS代码开头使用`*{margin:0px; padding:0px;}`对所有元素进行重置,确保所有浏览器都有一致的默认样式。 2. **链接样式**:`a{text-decoration:none;}`用于移除链接的下划线,提供更整洁的...
<link rel="stylesheet" type="text/css" href="src/assets/css/reset.css" rel="external nofollow" >/*引入公共样式*/ ``` 这样,在浏览器加载 index.html 文件时,公共的 CSS 文件将被加载。 方法三:在组件中...
浏览器之间默认的CSS样式存在差异,因此使用Reset CSS可以消除这些差异,实现跨浏览器兼容。然而,全局Reset(如`*{margin:0;padding:0;}`)应避免使用,因为它会降低效率,且可能对不必要的元素产生副作用。推荐...
- `<noframes>`: 在不支持框架的浏览器中显示替代内容。 6. **标题标签:** - `<h1>-<h6>`: 从一级到六级的标题,用于文档标题层次结构。 7. **其他标签:** - `<b>`: 加粗文本。 - `<big>`: 增大字体大小。 ...
- `no-repeat`:不重复。 - `repeat-x`:只在水平方向重复。 - `repeat-y`:只在垂直方向重复。 #### 二、字体样式 Font **1. `font-family`**:设置字体系列。 - **示例**:`font-family: 'Arial', sans-...
使用CSS reset库可以有助于标准化这些差异。 6. **IE6下绝对定位的容器内文本无法正常选择** - 这是一个已知的IE6问题。可以通过设置`position: relative;`和`z-index`来解决。 7. **CSS双线凹凸边框** - 可以...
CSS Reset是一种重置浏览器默认样式的技巧,目的是消除不同浏览器之间由于默认样式带来的差异,确保跨浏览器的一致性。 ```css *{ margin: 0; padding: 0; } ``` 此段代码将所有元素的`margin`和`padding`设置为0...
- `counter-increment` 和 `counter-reset` 用于计数器操作。 - `quotes` 设置嵌套引用的引号类型。 - `height`, `max-height`, `max-width`, `min-height`, `min-width`, `width` 控制元素尺寸。 - `bottom`, `...
- `reset.css`:用于清除浏览器默认样式,确保跨浏览器一致性。 - `master.css`:主样式文件,包含全局样式。 - `layout.css`:布局样式,定义页面结构。 - `columns.css`:处理列布局。 - `font.css`:字体...
5. **自定义CSS reset**:可能包含了重置浏览器默认样式的代码,确保跨浏览器的一致性。 通过这个项目,学习者可以了解并实践HTML和CSS的基础,以及如何在无框架的情况下创建一个完整的网站界面。这不仅有助于提升...
- 重置样式:reset.css - 用于清除浏览器默认样式,确保所有元素样式的一致性。 - 主要样式:master.css - 包含全局和基本样式。 - 布局样式:layout.css - 定义页面整体结构和布局。 - 列表样式:columns.css -...
滚动条通常通过`<frame>`的`scrolling`属性来控制,可设置为`yes`、`no`或`auto`。 2. **按钮类型**:HTML中的`<input>`标签用于创建不同类型的按钮,如`type="submit"`(提交按钮)、`type="reset"`(重置按钮)、...
可选值有`repeat`(图像在两轴重复)、`no-repeat`(不重复)、`repeat-x`(仅水平重复)、`repeat-y`(仅垂直重复)。 4. `background-color`: 设置元素的背景颜色。 **CSS边框属性(Border 和 Outline)** 1. `...
8. **内容生成**(Generated Content):CSS3引入了生成内容属性,如`content`用于在元素中插入内容,`counter-increment`和`counter-reset`管理计数器,常用于自动生成编号。 以上属性和用法都是在所有主流浏览器...