實現CSS重置的最佳方法是什么[重復]

[英]What is the best way to implement CSS reset [duplicate]


Possible Duplicate:
Best css reset

可能重復:最佳css重置

What is the best way to implement CSS reset? My question is more in context of implementing layouts which would be cross-browser, cross-platform compliant. E.g. layout should look similar on desktop browsers like ie, firefox and even on iPad and to some extent on iPhone as well.

實現CSS重置的最佳方法是什么?我的問題更多是在實現跨瀏覽器,跨平台兼容的布局的背景下。例如。布局應該在桌面瀏覽器上看起來類似,例如firefox,甚至在iPad上,在某種程度上也可以在iPhone上使用。

Please let me know if I should apply CSS reset to acheive this.

如果我應該使用CSS重置來實現這一點,請告訴我。

4 个解决方案

#1


3  

You could use normalize.css:

你可以使用normalize.css:

Normalize.css is a customisable CSS file that makes browsers render all elements more consistently and in line with modern standards. We researched the differences between default browser styles in order to precisely target only the styles that need normalizing.

Normalize.css是一個可自定義的CSS文件,它使瀏覽器更加一致地呈現所有元素並符合現代標准。我們研究了默認瀏覽器樣式之間的差異,以便僅精確定位需要規范化的樣式。

I don't know how well it supports mobile, tablets, etc., however.

但我不知道它對移動設備,平板電腦等的支持程度如何。

#2


4  

What's the best way to implement CSS reset?

實現CSS重置的最佳方法是什么?

Before answering your question, I think it's important to understand what a CSS reset is and is not going to do for you.

在回答您的問題之前,我認為理解CSS重置是什么並且不會為您做什么很重要。

What CSS Resets Do

The purpose of a CSS reset is to override the default styles that browsers use. That's about it.

CSS重置的目的是覆蓋瀏覽器使用的默認樣式。就是這樣。

There are a bunch of suggested styles that you'll probably find between most popular CSS resets that help to normalize some of the lesser-used elements. Additionally, there are a few necessary styles to make some browsers render HTML5 elements correctly.

你可能會在大多數流行的CSS重置之間找到一堆建議的樣式,這些重置有助於規范化一些較少使用的元素。此外,還有一些必要的樣式可以使某些瀏覽器正確呈現HTML5元素。

What CSS Resets Don't Do

Magic. Seriously, they're not a panacea. You'll still have to write a bunch more CSS to get a nice looking webpage. Just because your site uses a CSS reset doesn't mean that your site is better than another that doesn't. Many very attractive sites don't bother with a CSS reset, because they know they're going to override everything as part of the process anyway.

魔法。說真的,他們不是靈丹妙葯。你仍然需要編寫更多的CSS才能獲得漂亮的網頁。僅僅因為您的網站使用CSS重置並不意味着您的網站比其他網站更好。許多非常有吸引力的網站都不會為CSS重置而煩惱,因為他們知道無論如何都會覆蓋所有內容。

When should you use a CSS reset?

You should use a CSS reset when you're not planning on styling elements much beyond their defaults. It's really helpful for normalizing margins, padding and font-size on block-level text elements such as h#, p, blockquote, ul and ol.

當你沒有計划超出默認值的樣式元素時,你應該使用CSS重置。在塊級文本元素(如h#,p,blockquote,ul和ol)上標准化邊距,填充和字體大小非常有用。

When shouldn't you use a CSS reset?

You should not use a CSS reset when you're just blindly linking in someone elses CSS reset without any thought for what it's going to do to your layout. If you don't understand exactly what it's doing with your layout, you shouldn't be using it to begin with.

當您只是盲目地鏈接某人的CSS重置而不考慮它將對您的布局做什么時,您不應該使用CSS重置。如果你不清楚它對你的布局做了什么,你不應該開始使用它。

I usually don't recommend plain CSS resets to people because you often find style like * { margin: 0; padding: 0; } which are not helpful. At best you're going to force yourself to use higher specificity for other selectors down the road, and at worst, you're going to run into all sorts of style inheritance issues.

我通常不建議對人們進行簡單的CSS重置,因為你經常會找到類似* {margin:0;填充:0;這沒有用。在最好的情況下,你將強迫自己對其他選擇器使用更高的特異性,在最壞的情況下,你將遇到各種樣式繼承問題。

Instead of using a plain-jane reset, use a reset template, but fill in the styles for the elements you know. Instead of always having:

使用重置模板,而不是使用簡單的重置模板,但填寫您知道的元素的樣式。而不是總是:

p
{
  margin: 0;
  padding: 0;
}

you should set it to what the default paragraph style will be (if you're working with a design from someone else, style guides typically specify most of the styles that belong in a reset stylesheet):

您應該將其設置為默認的段落樣式(如果您使用其他人的設計,樣式指南通常會指定屬於重置樣式表的大多數樣式):

p
{
  border-bottom: 1px solid #000;
  margin: 0 0 1em;
  padding: 0 0 1em;
}

tl; dr.

Don't just blindly use a reset from someone else. Instead, pick out the useful styles that will actually be used, and specify useful defaults. There's no point to a CSS reset if you're only going to override everything in your default stylesheet anyway.

不要盲目地使用別人的重置。相反,選擇實際使用的有用樣式,並指定有用的默認值。如果您只是要覆蓋默認樣式表中的所有內容,那么CSS重置是沒有意義的。

I typically call my "reset" stylesheets my core.css because it contains all of my core styles to the layout that i'm trying to produce

我通常將我的“重置”樣式表稱為core.css,因為它包含了我正在嘗試生成的布局的所有核心樣式

#3


1  

If you go to CSS frameworks, such as Blueprint and 960.gs and download their CSS packages, you will find the reset.css and other default css that we should use before designing a site. Just use those.

如果你去CSS框架,比如Blueprint和960.gs並下載他們的CSS軟件包,你會發現在設計網站之前我們應該使用reset.css和其他默認的css。只是使用那些。

#4


1  

Meyerweb CSS Reset Stylesheet

Meyerweb CSS重置樣式表

This is what's recommended by most usually, it's what I use and I think it's the best out there.

這是最常見的建議,它是我使用的,我認為它是最好的。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2011/08/22/724d455f545d6d31fd4aeebf4f5eb0a8.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com