bottom没有效果,css 设置margin-top或margin-bottom失效不取作用的解决方法

html-css032

bottom没有效果,css 设置margin-top或margin-bottom失效不取作用的解决方法,第1张

首先来看一个案例:

.bottom-box{

margin -top:30px

}

我设置了margin-top属性,我的上边距应该距离父元素为30px

可是结果如何呢?结果并不是class为bottom-box的div上边距离父元素30px而是距离body元素30px

什么原因呢?

当个子元素设置margin-top属性时,如何父元素没有设置padding属性,即padding属性为0,那么会出现以上这个情况。

再来看一个实例:

http://www.manongjc.com/article/1263.html

其在IE6和IE7下显示效果为

margin:20px只有margin-bottom失效了。

解决办法:只要在浮动的最后一个元素后面加上“

.float_div{float:leftmargin:20pxwidth:100pxheight:100pxdisplay:inlinebackground-color:#CCC}

.clear{clear:both}

还有个简单点的解决方法:

IE6/7下margin-bottom无效一般出现在容器里某元素设置后在父容器内无效,这个时候只需要在父容器中加入以下两句css,基本上所有的浏览器都兼容了:

overflow:hiddenzoom:100%

这个方法不用添加额外的标签,也是很好的解决办法!

你好!

给body加个父级属性,给bottom加个子级属性。然后设置bottom定位位置底部。

例如body{position:relative}

.bottom:{position:absolutebottom:0}

希望对你有所帮助,望采纳。

语法: bottom : auto | length

取值: auto :  默认值。

无特殊定位,根据HTML定位规则在文档流中分配

length :  由浮点数字和单位标识符组成的长度值 | 百分数。必须定义 position 属性值为 absolute 或者 relative 此取值方可生效。

说明:检索或设置对象与其最近一个具有定位设置的父对象底边相关的位置。此属性仅仅在对象的定位( position )属性被设置时可用。否则,此属性设置会被忽略。此属性对于 currentStyle 对象而言是只读的。对于其他对象而言是可读写的。对应的脚本特性为 bottom 。其值为一字符串,所以不可用于脚本(scripts)中的计算。请使用 style 对象的 posBottom , pixelBottom 等运行时特性。

示例: div { position: absolutebottom: 1in} div { position:relativebottom:6px}