浮动div css下的页边距顶部
我在float下面有一个div:right div。由于某些原因,上边距不能应用于第一个div。下面是css浮动div css下的页边距顶部,css,margin,Css,Margin,我在float下面有一个div:right div。由于某些原因,上边距不能应用于第一个div。下面是css #over{ width:80%; float:right; color:#e68200; } #under{ clear:both; background:url(../images/anazitisi.png) no-repeat; margin:10px auto; /*does not work!!!*/ width:95px; heig
#over{
width:80%;
float:right;
color:#e68200;
}
#under{
clear:both;
background:url(../images/anazitisi.png) no-repeat;
margin:10px auto; /*does not work!!!*/
width:95px;
height:20px;
}
有人知道发生了什么吗?浮动的东西有点脱离了正常的布局,所以通常不会影响其他不像它们那样浮动的东西。当然,不同浏览器中的浮动行为是不同的,但这只是一般的想法 在浮动div之后,您需要一些东西(比如空div)来清除浮动(has style=“clear:both;”)
然而,正如我所说,浏览器行为仍然会有所不同,取决于它决定从何处计算利润。当然也有解决办法 试试这个css狙击,我想这会解决你的问题
#over{
width:80%;
float:right;
color:#e68200;
background-color:#234fdd;
height:auto;
margin-bottom:30px;
}
#under{
clear:both;
background:url(../images/anazitisi.png) no-repeat;
margin:auto;
width:200px;
height:20px;
background-color:#23ffff;
}
没有额外的
您看到的是CSS3中的问题。随着CSS4的出现,这个问题将更容易解决。同时,添加一个额外的
,听起来很简单,这不是一个好主意。通常最好将内容和演示严格分开
下面是我如何解决这个问题的。该解决方案利用了内联块内没有垂直边距折叠的情况
下的#应至少包含以下项目:
#under {
clear: both;
display: inline-block;
width: 100%;
}