CSS: DIV containing no height on float set

后端 未结 4 1632
感动是毒
感动是毒 2020-12-02 23:34

assume we have this code:

4条回答
  •  无人及你
    2020-12-03 00:33

    Set #upperDiv any of the following:

    overflow: hidden;
    width: 100%;
    

    or

    float: left;
    width: 100%;
    

    or create a rule using CSS pseudo-elements (IE8+ compatible) like this

    #upperDiv:after {
      content: "";
      display: table;
      clear: both;
    }
    

    Best solution
    Creating a reusable class rule like the following.

    .group:after {
      content: "";
      display: table;
      clear: both;
    }
    

    Now you can apply it to anything that needs this same functionality. For example...

    P.S. If you require IE 6/7 compatibility, checkout this post.

提交回复
热议问题