- This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- The forum ‘Other’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
When centering something horizontally in CSS, a common solution for block level elements is:
margin: 0 auto;
So, to center vertically, why doesn’t
margin: auto 0;
work? Does anyone know why we can center horizontally like that, but not vertically?
EDIT:
I know it’s because the W3C spec says that
If ‘margin-top’, or ‘margin-bottom’ are ‘auto’, their used value is 0.
What I want to know is why they made it be 0 for top and bottom margins, but not for left and right margins.
What I want to know is why they made it be 0 for top and bottom margins, but not for left and right margins.
OK…the obvious answer is to ask the people who created the spec.
Other than that…I’d have to think about it.
It’s probably something really simple like there is no default height for block-level elements but there is for widths (100%).
@nkrisc and @shaneisme Thanks for answering, guys!
@nkrisc that definitely makes sense to me. Thanks for sharing those similarities with physical paper documents. Helped me visualize the reasoning better.