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

后端 未结 6 1937
慢半拍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:16

    There doesn't seem to be justify-self, but you can achieve similar result setting appropriate margin to auto¹. E. g. for flex-direction: row (default) you should set margin-right: auto to align the child to the left.

    .container {
      height: 100px;
      border: solid 10px skyblue;
      
      display: flex;
      justify-content: flex-end;
    }
    .block {
      width: 50px;
      background: tomato;
    }
    .justify-start {
      margin-right: auto;
    }

    ¹ This behaviour is defined by the Flexbox spec.

提交回复
热议问题