Inner left-floating div's do not expand the container div vertically

后端 未结 4 1088
孤独总比滥情好
孤独总比滥情好 2021-01-03 20:52

I have a container div with the following attributes:

#cat_container{
margin:0;
padding:5px;
border:1px solid red;
min-height:200px;
}

Insi

4条回答
  •  耶瑟儿~
    2021-01-03 21:27

    This is a common problem and is fixed using a "clearfix" solution. Setting overflow will fix this problem, however there are better solutions, like the following:

    .mydiv:after {
        visibility: hidden;
        display: block;
        font-size: 0;
        content: " ";
        clear: both;
        height: 0;
    }
    * html .mydiv             { zoom: 1; } /* IE6 */
    *:first-child+html .mydiv { zoom: 1; } /* IE7 */
    

    The main point of this solution is to trigger thehasLayoutproperty of the div. Fortunately it is enough for IE 6/7 to set the zoom to 1 in order to trigger that. Modern browsers which support the:afterpseudo element can use the first statement, which is cleaner and does not affect the overflow property.

    Please note that you should avoid using the!importantstatement as suggested in the earlier answer as that is not good css. Moreover it will not allow you to control the height of the div if you wish to and does not do anything to solve the problem.

提交回复
热议问题