2013-07-10 51 views
0

在固定位置的div我如何保证金值设置为固定定位的div

#abs{ 
position: fixed; 
bottom: 0; 
background-color: red; 
padding: 20px; 
width: 100%; 
margin-top: 200px; 
} 

margin-top: 200px;不起作用应用这个CSS。

这里是demo

是否有与jQuery的方法吗?

+0

顶部使用不仅没有边距使用顶部将扩大股利 – akash

+0

。但我需要差距之间的差距。 http://jsfiddle.net/T5yg7/8/ –

+0

我需要这样的http://jsfiddle.net/T5yg7/11/,但没有在小提琴的#someid设定保证金。 –

回答

2

固定定位从文档流中取出一个元素,所以不要弄乱元素的边距。如果你不能改变HTML尝试添加

body { 
    margin-bottom: 200px; 
} 

顺便说一句,如果你真的需要添加一些内容到页面的底部,但只能访问样式表,您可以使用此:

body:nth-last-child(1):after { 
    content: "aha "; 
    line-height: 200px; 
} 

http://jsfiddle.net/DomDay/QqMFX/

2

尝试给margin-bottom:200px; for the top div class #someid这也给出了同样的结果 Check This

编辑

添加position: relative;,而不是固定的,那么这将是工作。

#abs{ 
    position: relative; 
    bottom: 0; background-color: red; 
    padding: 20px; 
    width: 100%; 
    margin-top:200px; 
    } 

Check this

+0

我需要将#abs div设置为#someid。 –

+0

检查编辑答案 – Nithesh

+0

OP标题为“如何设置保证金值固定位置div”不相对:) – Praveen

0
#someid{ 
     position:absolute; 
     height: 700px; 
     background-color: yellow; 
     width: 100%; 
     } 
#abs{ 
    position:absolute; 
    background-color: red; 
    padding: 20px; 
    width: 100%; 
    margin-top:200px; 
    } 
-1

如果#abs#someid之间的空间是你的问题,然后有换行符<br />

入住这updated fiddle

更新: 如果你打开使用jquery然后检查这个fiddle

+0

我需要不接触html –

+0

检查我的更新答案为你工作。 – Praveen

+0

是的,可能是,但没有使用br,有没有办法在jQuery中使用css。 –