How to justify a single flexbox item (override justify-content)

后端 未结 6 1934
慢半拍i
慢半拍i 2020-12-07 07:11

You can override align-items with align-self for a flex item. I am looking for a way to override justify-content for a flex item.

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-07 07:21

    AFAIK there is no property for that in the specs, but here is a trick I’ve been using: set the container element ( the one with display:flex ) to justify-content:space-around Then add an extra element between the first and second item and set it to flex-grow:10 (or some other value that works with your setup)

    Edit: if the items are tightly aligned it's a good idea to add flex-shrink: 10; to the extra element as well, so the layout will be properly responsive on smaller devices.

提交回复
热议问题