Auto height of div

前端 未结 5 1112
被撕碎了的回忆
被撕碎了的回忆 2020-12-13 10:27

Browser shows div only when I set exact height. But i want to create resizable div according it\'s contents. Tried height: auto and height:100%. It doesn\'t help.

My

5条回答
  •  春和景丽
    2020-12-13 11:10

    div's will naturally resize in accordance with their content.

    If you set no height on your div, it will expand to contain its conent.

    An exception to this rule is when the div contains floating elements. If this is the case you'll need to do a bit extra to ensure that the containing div (wrapper) clears the floats.

    Here's some ways to do this:

    #wrapper{
    overflow:hidden;
    }
    

    Or

    #wrapper:after
    {
    content:".";
    display:block;
    clear:both;
    visibility:hidden;
    }
    

提交回复
热议问题