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

前端 未结 7 1469
别跟我提以往
别跟我提以往 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 19:58

    Flexbox can do that https://jsfiddle.net/2Lzo9vfc/210/

    HTML

    Box
    Box
    Box

    CSS

    .content {
        display: -webkit-flex;
        display: flex;
        -webkit-justify-content: space-around; 
        justify-content: space-around;
        width: 100%;
    }
    
    .box {
        background: black;
        padding: 25px;
        color: white;
    }
    

提交回复
热议问题