Fit div width to inline-block children

后端 未结 1 906
醉酒成梦
醉酒成梦 2021-01-19 06:27

I want the container div (#a-container in this example) to fit the width of its children, that are inline-block divs. In this example, I want the #a-container d

1条回答
  •  耶瑟儿~
    2021-01-19 06:48

    Here's a fiddle that uses display: table and floating: http://jsfiddle.net/vqjnoqur/.

    HTML:

    #a-container {
      display: table;
      background-color: gray;
    }
    
    .a {
      background-color:blue;
      width:100px;
      height: 100px;
      margin: 5px;
      float: left;
    }
    
    .a:nth-of-type(2n + 1) {
        clear: left;
    }

    0 讨论(0)
提交回复
热议问题