How do I automatically add spacing between divs without using percentage?

前端 未结 7 1445
别跟我提以往
别跟我提以往 2021-01-22 19:25

I have a few divs aligned horizontally. How do I make the spacing between them automatic so that if I resize the screen or add another div, there will be equal spacing between d

7条回答
  •  灰色年华
    2021-01-22 20:17

    You may use inline-block + text-align:justify; for older browser generating an extra last invisible line with :after, or flex + justify-content:space-betwween;

    .ib {
    text-align:justify;
      }
    .ib:after {
      content:'';
      display:inline-block;
      width:99%;
      }
    .flex {
      display:flex;
      justify-content:space-between;
      }
    .d100 {
      width:100px;
      height:2em;
      background:blue;
      display:inline-block;
      }

提交回复
热议问题