Margin behavior of “overflow:hidden” div after floating div on webkit

前端 未结 2 1710
青春惊慌失措
青春惊慌失措 2021-01-06 22:30

I\'ve found that an \"overflow:hidden\" div following a \"float:left\" div has doubled margin on the right. This can be tested with following code:



        
2条回答
  •  [愿得一人]
    2021-01-06 23:16

    The above solution seems to do the trick as long as the width of your floating element is static and predictable (as the margin of the non-floating div is set to span the floating div's width, plus the required space between the two).

    If, however, you're working with a floating div with a dynamic width, you can target what appears to be a Webkit-specific issue with a -webkit-margin-start property which all other browsers will ignore:

    .div.list {
        overflow: hidden;
        -webkit-margin-start: 0px !important; /* you can ditch the 'important' by adding 'div.intro' to the front of your selector */
    } 
    

    This effectively sets div.list's margin-left: 0 in Webkit only, while accommodating a dynamic width for your floating div. Unfortunately, I haven't been able to test this in Chrome 19b yet, so I'm not sure how it'll handle this kludge.

提交回复
热议问题