How to make a parent div grow with its children?

前端 未结 5 964
盖世英雄少女心
盖世英雄少女心 2020-12-30 00:49

How do I make a parent/container DIV grow as more children DIV\'s are added.

5条回答
  •  没有蜡笔的小新
    2020-12-30 01:29

    Adding display:flex to the parent div may work.

    For example, I wanted an unknown number of circles in a row, centered within an absolutely positioned div that expands as more are added in.

    #grandparent{
    
      width:300px;
      height:20px;
      position:absolute;
      right:30;
      bottom:30;
    
    }
    
    #parent{
    
      transform: translateX(-50%);
      left: 50%;
      position: absolute;
      display: flex;
    
    }
    
    
    .children{
    
       background-color: white;
       border-radius: 50%;
       width: 16px;
       height: 16px;
       margin-left: 3px;
       margin-right: 3px;
    
    }
    

    See https://codepen.io/anon/pen/zXwRza

提交回复
热议问题