Keep the middle item centered when side items have different widths

后端 未结 7 1111
长情又很酷
长情又很酷 2020-11-22 17:09

Imagine the following layout, where the dots represent the space between the boxes:

[Left box]......[Center box]......[Right box]

相关标签:
7条回答
  • 2020-11-22 17:59

    Here is another way to do it, using display: flex in the parents and childs:

    .Layout{
        display: flex;
        justify-content: center;
    }
    .Left{
        display: flex;
        justify-content: flex-start;
        width: 100%;
    }
    .Right{
        display: flex;
        justify-content: flex-end;
        width: 100%;
    }
    <div class = 'Layout'>
        <div class = 'Left'>I'm on the left</div>
        <div class = 'Mid'>Centered</div>
        <div class = 'Right'>I'm on the right</div>
    </div>

    0 讨论(0)
提交回复
热议问题