我知道什么是CSS重置,但最近我听说了一个叫Normalize.css的新东西
CSS和Reset CSS的区别是什么?
规范化CSS和重置CSS之间的区别是什么?
这只是CSS重置的一个新流行语吗?
我知道什么是CSS重置,但最近我听说了一个叫Normalize.css的新东西
CSS和Reset CSS的区别是什么?
规范化CSS和重置CSS之间的区别是什么?
这只是CSS重置的一个新流行语吗?
当前回答
Sometimes, the best solution is to use both. Sometimes, it is to use neither. And sometimes, it is to use one or the other. If you want all the styles, including margin and padding reset across all browsers, use reset.css. Then apply all decorations and stylings yourself. If you simply like the built-in stylings but want more cross-browser synchronicity i.e. normalizations then use normalize.css. But if you choose to use both reset.css and normalize.css, link the reset.css stylesheet first and then the normalize.css stylesheet (immediately) afterwards. Sometimes it's not always a matter of which is better, but when to use which one versus when to use both versus when to use neither. IMHO.
其他回答
css主要是一组样式,基于它的作者认为好看的样式,并使它在不同的浏览器中看起来一致。Reset基本上是从元素中剥离样式,这样你就可以更好地控制所有东西的样式。
我两者都用。
一些样式来自Reset,一些来自Normalize.css。例如,在Normalize.css中,有一种样式来确保所有输入元素都有相同的字体,这不会发生(在文本输入和文本区域之间)。Reset没有这样的样式,所以输入有不同的字体,这通常是不需要的。
所以基本上,使用两个CSS文件做一个更好的工作'均衡'一切;)
的问候!
这个问题已经回答过几次了,我将对每个问题进行简短的总结,并给出截至2019年9月的例子和见解:
css——顾名思义,它规范化了浏览器中用户代理的样式,也就是说,由于默认情况下它们略有不同,所以它们在所有浏览器中都是相同的。
示例:<h1>标签内<section>默认谷歌Chrome将使<h1>标签的“预期”大小更小。另一方面,Microsoft Edge正在使<h1>标签的“期望”大小。css将使其一致。
当前状态:npm存储库显示normalize.css包目前每周有超过50万的下载量。GitHub中项目库的星星超过36k。
重置CSS -顾名思义,它重置所有的样式,即它删除所有浏览器的用户代理样式。
示例:它会像下面这样做:
html, body, div, span, ..., audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
目前的状况:它远不如Normalize.css流行,reset-css包显示它每周大约有26k的下载量。GitHub的星星只有200,从项目的存储库可以看出。
我的工作是标准化。css。
主要的区别是:
Normalize.css preserves useful defaults rather than "unstyling" everything. For example, elements like sup or sub "just work" after including normalize.css (and are actually made more robust) whereas they are visually indistinguishable from normal text after including reset.css. So, normalize.css does not impose a visual starting point (homogeny) upon you. This may not be to everyone's taste. The best thing to do is experiment with both and see which gels with your preferences. Normalize.css corrects some common bugs that are out of scope for reset.css. It has a wider scope than reset.css, and also provides bug fixes for common problems like: display settings for HTML5 elements, the lack of font inheritance by form elements, correcting font-size rendering for pre, SVG overflow in IE9, and the button styling bug in iOS. Normalize.css doesn't clutter your dev tools. A common irritation when using reset.css is the large inheritance chain that is displayed in browser CSS debugging tools. This is not such an issue with normalize.css because of the targeted stylings. Normalize.css is more modular. The project is broken down into relatively independent sections, making it easy for you to potentially remove sections (like the form normalizations) if you know they will never be needed by your website. Normalize.css has better documentation. The normalize.css code is documented inline as well as more comprehensively in the GitHub Wiki. This means you can find out what each line of code is doing, why it was included, what the differences are between browsers, and more easily run your own tests. The project aims to help educate people on how browsers render elements by default, and make it easier for them to be involved in submitting improvements.
我在一篇关于normalization .css的文章中对此进行了更详细的描述
首先,css是你能使用的最糟糕的库,因为它删除了HTML的标准结构,在将空白填充和其他属性的值赋值为0之后,把你写的所有东西都作为文本显示出来。例如,你会发现<H1>和<H6>是一样的。
另一方面,css使用标准的结构,也修复了几乎所有存在的错误。例如,它解决了表单从一个浏览器显示到另一个浏览器的问题。Normalize通过修改这些特性来解决这个问题,这样你的元素在所有浏览器上的显示都是一样的。
css:每个浏览器都有一些默认的css样式,例如,在段落或标题周围添加填充。如果你添加了normalize样式表,所有这些浏览器默认规则将被重置,因此对于这个实例标签上的0px填充。这里有更多详细信息的链接:https://necolas.github.io/normalize.css/ http://nicolasgallagher.com/about-normalize-css/