how to make a div to wrap two float divs inside?

后端 未结 11 2169
野趣味
野趣味 2020-12-07 15:40

I don\'t know if it\'s a common problem, but I can\'t find the solution in web so far. I would like to have two divs wrapped inside another div, however these two divs insid

11条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-07 15:55

    Here's another, I found helpful. It works even for Responsive CSS design too.

    #wrap
    {
       display: table;
       table-layout: fixed; /* it'll enable the div to be responsive */
       width: 100%; /* as display table will shrink the div to content-wide */
    }
    

    WARNING: But this theory won't work for holder contains inner elements with absolute positions. And it will create problem for fixed-width layout. But for responsive design, it's just excellent. :)

    ADDITION TO Meep3D's ANSWER

    With CSS3, in a dynamic portion, you can add clear float to the last element by:

    #wrap [class*='my-div-class']:last-of-type {
      display: block;
      clear: both;
    }
    

    Where your divs are:

    >

    content

    }

    Reference:

    • :last-of-type - CSS-TRICKS

提交回复
热议问题