Equal width using flex and border-box

前端 未结 5 1386
悲&欢浪女
悲&欢浪女 2020-12-21 01:35

I am using box-sizing: border-box; with varying border thicknesses within a flexbox. I want the elements within the flexbox to have equal widths, b

5条回答
  •  粉色の甜心
    2020-12-21 02:01

    your problem is here flex: 1; change it to flex: 1 0 20%; even for more/less elements. no need to calculate the width using calc as others mentioned.

    also just change this:

    .container .block {
      height: 28px;
      flex: 1;
      border: 1px solid black;
      box-sizing:         border-box;
    }
    

    to:

    .container .block {
      height: 28px;
      flex: 1 0 20%;
      border: 1px solid black;
        -moz-box-sizing:    border-box;
      -webkit-box-sizing: border-box;
        box-sizing:         border-box;
    }
    

    DEMO: https://jsfiddle.net/4aww81wv/

提交回复
热议问题