2014-08-29 41 views
0

在HTML中,我尝试制作页脚,但是每次执行此操作时,都会在左侧添加页边距。新增保证金HTML

enter image description here

这是我的页脚代码;

<div id="footer"> tester </div> 
    #footer { 
    background-image: url(images/backgroundrpatternfooter.png); 
    background-repeat: repeat; 
    position : absolute; 
    bottom : 0; 
    height : 40px; 
    width : 1800px; 
    margin: 0; 
    } 
+0

可能这个'footer'包裹在另一个div上,有一些'margin:left'加入。 – 2014-08-29 10:01:29

+1

重新创建[jsFiddle](http://jsfiddle.net)。它将帮助其他人更好地进行调试。 – 2014-08-29 10:05:12

+0

尝试添加一个额外的属性到你的页脚css'clear:both;'而不是使用div与id页脚直接使用'

回答

-2

你的CSS表示固定的1800px但因为你的元素绝对定位,你需要添加一个margin-leftleft属性来指定元素应该从(margin-rightright也可以)进行定位。

你想让你的元素居中吗?尝试使用

left: 50% 

来实现这一点。

此外,尝试添加

left: 0; 

,看看能否消除你处理的差距。

(这个差距可能是由于你的元素比1800px宽)。

0

您的问题不在于页脚div,而是在body之内。该body元素具有8像素的默认保证金(可能取决于您使用的浏览器),所以你需要将body的边距设置为0这样的:

body { 
    margin: 0; 
} 

Working example.

我会也喜欢建议您考虑使用footer元素而不是使用div作为页脚,但为了这个目的,它被添加到HTML5中!

我希望这会有所帮助,祝你好运!

1
<div id="footer"> tester </div> 
#footer { 
    background-image: url(images/backgroundrpatternfooter.png); 
    background-repeat: repeat; 
    position : absolute; 
    bottom : 0; 
    height : 40px; 
    width : 1800px; 
    margin: 0; 
    **left:0;** 
} 

尝试添加左:0 ;,如果仍然无法检查您的继承CSS。