Centering in CSS: A Complete Guide
By Chris Coyier On centering, layout, vertical-align Centering things in CSS is the poster child of CSS complaining. Why does it have to be so hard? They jeer. I think the issue isn't that it's difficult to do, but in that there so many different ways of doing it, depending on the situation, it's hard to know which to reach for. So let's make it a decision tree and hopefully make it easier. I need to center... Horizontally Is it inline or inline-* elements (like text or links)? You can center inline elements horizontally, within a block-level parent element, with just: This will work for inline, inline-block, inline-table, inline-flex, etc. Is it a block level element? You can center a block-level element by giving it margin-left and margin-right of auto (and it has a set width, otherwise it would be full width and wouldn't need centering). This will work no matter what the width of the block level element you're centering, or the parent. Note that you can't float an element to the center.
Related: Tuto CSS 3
• Webdevelope (tricks)