开发者

Is there a need for zero-out DIV's margin and padding?

开发者 https://www.devze.com 2022-12-29 00:52 出处:网络
I wonder if on any browser div element comes with a preset margin/padding value other than zero. As far as I know, div and span come with zero padding and margin values by standard to make them suitab

I wonder if on any browser div element comes with a preset margin/padding value other than zero. As far as I know, div and span come with zero padding and margin values by standard to make them suitable c开发者_开发百科anvas for style decoration.

Even better, is there a definite standard for default styles for all elements that is cross-browser which we can make assumptions upon? For instance FORM comes with top/bottom margins, OL/UL come with padding-left's.

I occasionally see a

* {
  margin: 0; 
  padding: 0;
}

and this just looks like a dirty hack without knowing the reasons or consequences. Anyone has any better approach to this?


Different browsers have different defaults -- this is why using CSS resets like these

  • http://meyerweb.com/eric/tools/css/reset/
  • http://developer.yahoo.com/yui/reset/

are popular in order to insure that browsers are treating all the elements equally. It gives you a baseline and then expects you to define all the relevant styling.

0

精彩评论

暂无评论...
验证码 换一张
取 消