Home > DeveloperSection > Forums > How do I center block-elements with CSS1?
Goti Bandu

Total Post:119

Points:835
Posted on    December-13-2012 3:21 AM

 CSS-CSS3 CSS-CSS3 
Ratings:


 1 Reply(s)
 1039  View(s)
Rate this:
Hello every one

 In the last week, i googly about center block - element in CSS. so my question is that how do I center block-elements with CSS1?

Thanks in advance


AVADHESH PATEL

Total Post:604

Points:4228
Posted on    December-13-2012 6:24 AM

Hi Goti Bandu

There are two ways of centering block level elements:

1. By setting the properties margin-left and margin-right to auto and width to some explicit value: BODY {width: 30em; background: cyan;} P {width: 22em; margin-left: auto; margin-right: auto} In this case, the left and right margins will each be four ems wide, since they equally split up the eight ems left over from (30em - 22em). Note that it was not necessary to set an explicit width for the BODY element; it was done here to keep the math clean.

2. Another example: TABLE {margin-left: auto; margin-right: auto; width: 400px ;} in most legacy browsers, a table's width is by default determined by its content. In CSS-conformant browsers, the complete width of any element (including tables) defaults to the full width of its parent element's content area. As browser becomes more conformance, authors will need to be aware of the potential impact on their designs.


I hope your googly stoped here.

Don't want to miss updates? Please click the below button!

Follow MindStick