How to get tiles centered and left-justified at the same time

前端 未结 9 1934
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-30 10:33

I have a container of tiles (or divs) and I want the container to be centered, while the tiles are left justified in the container.

so if the window is small:

<
9条回答
  •  时光说笑
    2020-11-30 11:03

    This is pretty easy with flexbox.

    .container { display: flex; flex-wrap: wrap; }

    You can customize how the tiles fit as well, such as giving them a starting point (flex-basis) or how much the tile can grow or shrink

    .tile { flex-grow: 0; flex-shrink: 0; flex-basis: 3em;

    Check out the codepen: http://codepen.io/anon/pen/uexbf

提交回复
热议问题