Centering grid items in an auto-fill container

Flexbox The most efficient solution to your problem is probably flexbox, as flex items are not confined to individual tracks (columns/rows) like grid items. .grid { display: flex; flex-wrap: wrap; margin-bottom: 1em; } .item { flex: 1 0 100px; background: #eee; text-align: center; border: 1px dashed gray; box-sizing: border-box; } <div class=”grid”> <div class=”item”>Item 1</div> … Read more

zurb foundation center content in the grid

Edit November 2015: In Foundation 6 check out Typography Helpers Edit April 2014: In Foundation 5 check out Utility classes. Original answer: Use the text-center class. <div class=”row”> <div class=”twelve columns text-center”><br /> <img src=”https://stackoverflow.com/questions/12079049/img_06.jpeg” alt=”slide image”> </div> </div> Source: https://github.com/zurb/foundation/pull/224

How do I centre absolutely positioned content of unknown width?

Pushing the element left by 50% of its width and then translating it horizontally by 50% has worked for me. .element { position: absolute; left: 50%; transform: translateX(-50%); } I found the concept in the following link, and then I translated to fit my horizontal align needs: https://gist.github.com/colintoh/62c78414443e758c9991#file-douchebag-vertical-align-css