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
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.
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
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.