Equal width using flex and border-box

前端 未结 5 1385
悲&欢浪女
悲&欢浪女 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 01:46

    One way could be setting a 2px padding to the .block and removing it for .selected

    .container {
      display: flex;
      flex-direction: row;
      align-items: center;
      width: 100px;
    }
    
    .container .block {
      height: 28px;
      flex: 1;
      border: 1px solid black;
      box-sizing: border-box;
      padding: 2px;
    }
    
    .container .block.selected {
      border: 3px solid blue;
      padding: 0px;
    }
    0 1 2 3 4

提交回复
热议问题