解决子div撑不开父div

今天项目遇到问题记录,找了半天的方法都好像都不适用我的....最后大佬两句话解决,记录下来希望对小伙伴们有用

百度解决方法:

方法一:推荐

设置父div的overflow:hidden;

自己结果(仅供参考):此方法我的会把多余的隐藏.然而并不是我想要的结果(撑开)

方法二:
父div结束前增加一个空div style=”clear:both;”

[html]  view plain  copy
  1. .clear {  
  2.   clear:both;  
  3. }  
  4.   
  5. <div>  
  6.   <div style=”float:left;”>  
  7.   <div class=” clear” ></div>  
  8. </div>  

自己结果(仅供参考):没看到效果

方法三:这是一位大佬谷歌翻译找出来的

扫描二维码关注公众号,回复: 949164 查看本文章

[html]  view plain  copy
  1. .clearfix:after {  
  2.   content: ".";  
  3.   display: block;  
  4.   height: 0;  
  5.   clear: both;  
  6.   visibility: hidden;  
  7. }  
  8. /* Hides from IE-mac \*/  
  9. * html .clearfix {  
  10.   height: 1%;  
  11. }  
  12. /* End hide from IE-mac */  

自己结果(仅供参考):和2方法差不多


方法四:设定高,或者js动态设置(不推荐,css能解决的不用js)


我最后解决方法:

子div 加 position:static   父div加  height:auto

我项目完美解决 ,也许我的就是这样,仅供参考  错了提出来 勿喷!谢谢

猜你喜欢

转载自blog.csdn.net/qq_37415950/article/details/80303656
今日推荐