View Full Version : Centering A Table Using CSS
AlistairH
06-24-2005, 02:37 PM
OK! I'm thick! What's the CSS positioning code for aligning a table on the center of a page, either horizontally, vertically or both?
jscheuer1
06-24-2005, 06:31 PM
They haven't decided yet. Try:
table {
margin:0 auto;
}
* html table {
margin: 0 20%:
}
That's horizontal centering, I imagine vertical would be the opposite and both would be auto auto and 20% 20% respectively but, vertical centering is an odd concept and might not be supported.
mwinter
06-24-2005, 08:41 PM
They haven't decided yet.It was decided years ago. Blame browser manufactures for poor (or no) implementation.
See http://css-discuss.incutio.com/?page=CenteringBlockElement. Note that vertical centring is a real pain in the ass because of poor CSS support, particularly from IE.
That's horizontal centering, I imagine vertical would be the opposite and both would be auto auto and 20% 20% respectivelyNo, that wouldn't work without extra effort, but it's close:
<selector> {
position: absolute;
height: ...;
margin: auto 0;
top: 0; bottom: 0;
}If you added similar declarations for horizontal dimensions, you'd get horizontal centring, too. However, you can guess where this doesn't work. :rolleyes:
Mike
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.