Child div in parent div, float:left

前端 未结 3 939
孤街浪徒
孤街浪徒 2020-12-18 08:10

Please take a look at my code: http://jsfiddle.net/XptrZ/ Why are\'nt the blue divs inside the red one, and why the red one has height=0. How can I solve this? Thanks

相关标签:
3条回答
  • 2020-12-18 08:20

    Add one extra and empty div to parent div with this format:

     <div style="clear:both"></div>
    
    0 讨论(0)
  • 2020-12-18 08:23

    add overflow: hidden to parent

    .parent {
      background-color: gold;
      border: 1px solid gold;
      position: relative;
      overflow: hidden
    }
    
    .child {
      float: left;
      width: 100px;
      height: 100px;
      display: block;
      margin: 10px;
      background-color: pink;
      border: 1px solid #999;
    }
    <div class="parent">
      <div class="child">div1</div>
      <div class="child">div2</div>
      <div class="child">div3</div>    
    </div>

    0 讨论(0)
  • 2020-12-18 08:44

    add display: table; inside parent. That'll work.

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