不使用 CSS 重置的原因是什么?
我听说很多开发者不推荐使用CSS重置,原因是什么?
例如: 可移植 CSS 的规则是什么?
I heard that many developers are not recommending using CSS reset, what are the reason for it?
for example:
What are the rules for portable CSS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当使用 CSS 重置时,许多 HTML 元素变得不可用:标题很小,无边框且无边距,输入元素格式错误,等等...您需要重新设置所有这些元素的样式,这需要更多工作。
有些人认为这种去样式化/重新样式化的过程是不必要的,容易出错,并且它消除了平台之间一些必要的差异。最值得注意的是,输入元素通常由浏览器根据其主机平台(Windows、Mac 等)设置样式,并且有些人认为即使在浏览器内部也应该尊重 UI 一致性。
When using a CSS reset, lots of HTML elements become unusable : titles are small border-less and margin-less, input elements are misformed, etc... You need to restyle all these elements, which is more work.
Some people think that this process of destyling/restyling is unnecessary, error-prone, and that it removes some necessary differences between platforms. Most notably, input elements are typically styled by a browser according to its host platform (windows, mac, etc...) and some people think that UI consistency should be respected even inside a browser.
CSS Reset 可以跨浏览器标准化 CSS,并为您提供更简单、更直观的设计可能性。
例如,当您在没有 CSS 重置/规范化的情况下使用
时,它将具有更大的
font-size
、一些margin
,和粗体font-weight
,通过 CSS 重置,它看起来像普通文本,并且允许您按照自己想要的方式塑造它,而不必担心浏览器默认值可能会因浏览器而异。您应该问自己的问题是,您想要它吗?
请记住,CSS 重置不必是绝对的,如果您想删除所有边距和填充,但保留字体大小和粗细,您可以使用经典的
* { padding: 0;保证金:0; }
而不是使用全功能的 CSS 重置。CSS Reset is found there to normalize the CSS across browsers and gives you easier and more intuitive design possibilities.
For instance, when you use
<h1>
without a CSS reset/normalization, it will have largerfont-size
, somemargin
s, and a boldfont-weight
, with a CSS reset, it would look like a normal text, and it allows you to shape it the way you want, without worrying about the browser defaults which may vary between browsers.The question you should ask yourself, do you want it?
Remember that a CSS reset does not have to be absolute, if you want to remove all margins and paddings, but retain font size and weight, you could use the classic
* { padding: 0; margin: 0; }
rather then using a full-powered CSS reset.如果您正在制作一个网站,
你知道 html & CSS就像你的手的背面,
并且您可以直接在所有主要操作系统上进行测试而无需妥协,
您擅长纠正旧浏览器的错误/冲突,
或者您正在制作仅适用于一种浏览器的网站。
您可能不需要重置 CSS,或者您最好自己重置 CSS。
但如果您正在制作一个典型的现代网站并且您想避免
跨浏览器冲突,重置表应该将 html 元素“设置”为类似的
比赛场地。
许多重置表对样式的干扰太大,您真正想要的只是默认值,例如 CSSesta 或 埃里克·迈耶的
If you are making a website,
and you know html & CSS like the back if your hand,
and you can test directly on all major operating systems without compromise,
You're proficient in correcting errors/conflicts with old browsers,
or you are making a website for one browser only.
You may not need a CSS reset or it would be best for you to make your own.
But if you're making a typical modern website and you want to avoid
cross browser conflicts, a reset sheet should "set" the html elements to a similar
playing field.
Many reset sheets interfere with styling too much, all you really want is a default like CSSesta or Eric Meyer's