Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do margin:5px 0; and margin:5px 0 0; mean?

Tags:

css

Does margin:5px 0; mean margin:5px 0 0 0; or margin:5px 0 5px 0;?

Does margin:5px 0 0; mean margin:5px 0 0 0;?

Same for padding of course.

Also, is it consistent across all browsers (including IE6)?

like image 474
Darryl Hein Avatar asked May 04 '09 08:05

Darryl Hein


People also ask

What does margin 10px 5px 15px 20px mean?

margin: 10px 5px 15px 20px; top margin is 10px. right margin is 5px. bottom margin is 15px. left margin is 20px.

What does margin 0 padding 0 mean?

For zero padding, imagine putting a box into a box where the inner box is just slightly smaller so it fits perfectly. There is no space between the inner (content) box and the outer (border) box so there is zero padding. Margin is just the space outside the border.

What does it mean when margin is 0?

0 is for top-bottom and auto for left-right. It means that left and right margin will take auto margin according to the width of the element and the width of the container. Generally if you want to put any element at center position then margin:auto works perfectly.

What does the margin element do?

Margins are used to create space around elements, outside of any defined borders. This element has a margin of 70px.


1 Answers

According to Box Model:

  • If there is only one value, it applies to all sides.
  • If there are two values, the top and bottom margins are set to the first value and the right and left margins are set to the second.
  • If there are three values, the top is set to the first value, the left and right are set to the second, and the bottom is set to the third.
  • If there are four values, they apply to the top, right, bottom, and left, respectively.
body { margin: 2em }         /* all margins set to 2em */ body { margin: 1em 2em }     /* top & bottom = 1em, right & left = 2em */ body { margin: 1em 2em 3em } /* top=1em, right=2em, bottom=3em, left=2em */ 

This is defined by the CSS standard, so it should be consistent across all browsers that implements CSS correctly. For browser compatibilities, check out blooberry's CSS Support History and quirksmode. According to blooberry, margin was first implemented in IE3, so IE6 should be fine.

like image 61
Eugene Yokota Avatar answered Sep 19 '22 23:09

Eugene Yokota