Keep the middle item centered when side items have different widths

后端 未结 7 1235
长情又很酷
长情又很酷 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:47

    You can do this like so:

    .bar {
        display: flex;    
        background: #B0BEC5;
    }
    .l {
        width: 50%;
        flex-shrink: 1;
        display: flex;
    }
    .l-content {
        background: #9C27B0;
    }
    .m { 
        flex-shrink: 0;
    }
    .m-content {    
        text-align: center;
        background: #2196F3;
    }
    .r {
        width: 50%;
        flex-shrink: 1;
        display: flex;
        flex-direction: row-reverse;
    }
    .r-content { 
        background: #E91E63;
    }
    This is really long content. More content. So much content.
    This will always be in the center.
    This is short.

提交回复
热议问题