{"id":181375,"date":"2014-09-02T09:56:39","date_gmt":"2014-09-02T16:56:39","guid":{"rendered":"http:\/\/css-tricks.com\/?p=181375"},"modified":"2021-08-02T07:45:40","modified_gmt":"2021-08-02T14:45:40","slug":"centering-css-complete-guide","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/centering-css-complete-guide\/","title":{"rendered":"Centering in CSS: A Complete Guide"},"content":{"rendered":"\n
Centering things in CSS is the poster child of CSS complaining. Why does it have to be so hard?<\/em> 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.<\/p>\n\n\n\n So let’s make it a decision tree and hopefully make it easier.<\/p>\n\n\n\n\n\n\n\n I need to center…<\/p>\n\n\n\n You can center inline elements horizontally, within a block-level parent element, with just:<\/p>\n\n\n\n\n
Horizontally<\/h3>\n <\/summary>\n \n\n
\n Is it inline or inline-* elements (like text or links)? <\/summary>\n \n\n
.center {\n text-align: center;\n}<\/code><\/pre>\n\n\n\n