Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何在网页上居中放置页脚div_Html_Css - Fatal编程技术网

Html 如何在网页上居中放置页脚div

Html 如何在网页上居中放置页脚div,html,css,Html,Css,我想将我的网页页脚居中,并在它和上面的内容之间创建一个合理的gab。目前,页脚有一行和一段与上述内容相连。我可以向下推内容,但线不会移动。我确信css样式表中缺少的属性。有人能帮忙吗 这是我的html标记: <div id="footer"> <p>Copyright (c) 2010 mysite.com All rights reserved</p> </div> 版权所有(c)2010 mysite.com保留所有权利 我可以使

我想将我的网页页脚居中,并在它和上面的内容之间创建一个合理的gab。目前,页脚有一行和一段与上述内容相连。我可以向下推内容,但线不会移动。我确信css样式表中缺少的属性。有人能帮忙吗

这是我的html标记:

<div id="footer">
   <p>Copyright (c) 2010 mysite.com All rights reserved</p>
</div> 

版权所有(c)2010 mysite.com保留所有权利


我可以使用哪个css属性来解决此问题?请提供样品。谢谢。

将一个div水平居中?通常通过设置
margin:0 auto
,或
margin left:auto;右边距:自动

#footer{
text-align:center
}

如果你想在上面留一个间隙,给它一个上边距。

使用margin:auto-to-center blocks和CSS,使用margin-top或padding-top在上面留一个间隙:

#footer {
    margin-left:auto;
    margin-right:auto;
    margin-top:2em;
}
我使用了2em作为上边距;您可以随意更改,如果愿意,甚至可以更改为固定像素大小。您也可以使用padding top,也可以使用padding top,也可以使用padding top代替margin top,具体取决于您需要实现的功能,尽管居中只能使用margin left/right,而不能使用padding

上述代码可以使用简写边距代码进行压缩,这样您就可以在同一行代码中列出它们:

#footer {
    margin: 2px auto 0 auto;
}
(顺序为上、右、下、左)


希望有帮助。

您可以使用以下CSS将文本居中

#footer {
  margin: 0 auto;
}
如果您想在顶部增加更多空间,请添加

margin-top: 2em;
在上一页边距线之后。请注意,顺序很重要,所以如果您首先有
页边距顶部
,它将被
页边距
规则覆盖


页脚上方的更多空白垂直间距也可以使用

padding-top: 2em;
可以了解
边距
填充
之间的区别。主要的一点是
margin
div
元素的边框上方留出空间,作为
填充
div
内部留出空间。使用哪个属性取决于其他页面元素的属性。

我用以下方法解决了这个问题:

#footer {
width: 100%;
height: 28px;
border-top: 1px solid #E0E0E0;
position: absolute;
bottom: 0px; 
left: 0px; 
text-align: center; 
}

我使用此代码作为底层版权

.footer-copyright {
    padding-top:50px;
    display: table;
    text-align: center;
    margin-left: auto;
    margin-right: auto;
}
注:

  • #
    Panel1是DIV的id,上面的代码是CSS
  • DIV必须足够大以包含这些项,这一点很重要 在它里面

我们可以查看您的全部代码吗?如果我能看到代码,我相信我能在5分钟内解决你的问题。那就是#footer-div的ID是footer,而不是classe。所有要做的就是对齐文本,而不是对齐div本身。块元素占用整个可用宽度,如果不指定它,你不能将它们居中,但有带文本的内联子元素:align:center;您好,有人能告诉我为什么页脚在一个页面上正常工作,而在另一个页面上,页脚在网页的中间位置与数据混合。您可能需要为这种情况创建一个单独的问题,并提供足够的解释。你也应该考虑接受这个问题的答案。保证金与填充顶部不同吗?在这种情况下,padding top不是更适用吗?margin在#footer元素之外,padding在它里面。我没有采纳这些新建议,但根据我之前提交的内容,我发现页脚集中在一页上,而另一页有大量数据,页脚不在页面底部,而是在数据本身的中间。课程可能是什么?他可能想把文本放在中心,而不是div本身。默认情况下,div将跨越整个宽度,因此只有在同时提供宽度的情况下才有意义。我使用的是:#footer{width:920px;height:100px;margin:0 auto;margin top:2em;padding:0;border top:1px solid#和#footer p{边距:1;填充:30px 0px 0px 0px;文本对齐:居中;行高:正常;字体大小:12px;}
.copyright {
    margin: 10px auto 0 auto;
    width: 100%;
    font-family: Verdana, Geneva, sans-serif;
    font-size: 10px;
    font-style: normal;
    text-align: center;
    color: #ccbd92;
    border-top: 1px solid #ccbd92;
}
.footer-copyright {
    padding-top:50px;
    display: table;
    text-align: center;
    margin-left: auto;
    margin-right: auto;
}
    #Panel01 {

    vertical-align:bottom;
    bottom: 0;
     margin-left:auto;
     margin-right:auto;
     width: 400px;
    height: 100px;
}