When do nested child elements expand their parent elment?

前端 未结 2 882
陌清茗
陌清茗 2021-01-20 21:55

In many places I have put elmeents nested in other elements. I can\'t deduce when a child element causes the parent element to expand. I don\'t have any code to post as th

2条回答
  •  滥情空心
    2021-01-20 22:21

    Get firebug for firefox. You can browse the DOM (the HTML structure of the page) and it will highlight elements according to how the "browser's eye" sees them (versus how they look aesthetically).

    A few general rules of thumb:

    • Children will expand their parent's height as long as they're not floated or absolutely positioned, but...
    • You can "clear" a series of floated images http://www.quirksmode.org/css/clearing.html to make the parent element expand
    • If you use top positioning for a relatively positioned child element, the browser will still see that element in the exact same place. In other words the height of the parent element will stay the same regardless of where the child is relatively positioned to.
    • Using positive or negative margins on a child that is display: block will add or subtract height from its parent

提交回复
热议问题