Center parent div with float children

前端 未结 4 1875
逝去的感伤
逝去的感伤 2021-01-24 12:09

Parent hasnt got a defined width because there are unknown number of children inside.

Why do children fall into new line and how to prevent that? Children need to be on

4条回答
  •  礼貌的吻别
    2021-01-24 12:16

    Use center class :

    .wrap {
      text-align: center;
      margin: 50px auto 0 auto;
      height:40px;
    }
    
    .center {
      display: inline-block;
    }
    
    .box {
     width: 40px;
     height:40px;
     float:left;
     background:red;
     margin-right:1px;
    }
    
    @media all and (max-width: 474px) {
      .box {
        width: 25px;
      }
    }
    0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10

提交回复
热议问题