Html 将可扩展div块居中

Html 将可扩展div块居中,html,css,Html,Css,似乎无法理解此代码不起作用的原因。我希望按钮在页面底部居中。我有代码让它们停留在页面底部,但我就是不能让它们居中。除非我使用,但这不是“感觉”这样做的方式 请参见JSFIDLE上的示例: HTML: 非常感谢您的提示。您能试试这个吗,添加了边距:0.25% CSS: HTML: 但是01 但是02 但是03 但是04 演示:试试这个: CSS: 您还需要从html标记中删除style=“margin:auto;”“。将样式文本align:center应用于页脚元素或CSS <div

似乎无法理解此代码不起作用的原因。我希望按钮在页面底部居中。我有代码让它们停留在页面底部,但我就是不能让它们居中。除非我使用,但这不是“感觉”这样做的方式

请参见JSFIDLE上的示例:

HTML:


非常感谢您的提示。

您能试试这个吗,添加了
边距:0.25%

CSS:

HTML:


但是01
但是02
但是03
但是04
演示:

试试这个:

CSS:


您还需要从html标记中删除
style=“margin:auto;”“

将样式文本align:center应用于页脚元素或CSS

<div id ="footer" style="margin:auto;text-align:center;">

您可以使用align='center'

    <div id ="footer" align='center' >
       <div class="nails-footer-buttons">But01</div>
       <div class="nails-footer-buttons">But02</div>
       <div class="nails-footer-buttons">But03</div>
       <div class="nails-footer-buttons">But04</div>
    </div> 

但是01
但是02
但是03
但是04

这不是最好的方法,但它应该可以工作

当div的位置固定时,不能通过添加margin:auto来居中div。相反,添加左:50%和左边距:-div宽度的50%;你能给我解释一下为什么会这样吗?顺便说一句,它确实有效,但我想知道它的影响。嗯,它没有完全居中,如果我看得正确,我将不得不基于页面宽度重新计算百分比。有效!但为什么这不是最好的方法呢?我以后会遇到问题吗?你不应该有任何问题,只是html5不支持它,所以如果你试图让你的网站运行最新的代码,那么它可能不是最好的方法:)
#footer{        
    position: fixed;
    bottom: 0;
    width: 100%;
    margin:0 25%;
}
<div id ="footer" >
    <div class="nails-footer-buttons">But01</div>
    <div class="nails-footer-buttons">But02</div>
    <div class="nails-footer-buttons">But03</div>
    <div class="nails-footer-buttons">But04</div>
</div> 
  #footer{        
            position: fixed;
            bottom: 0;
            left:50%;
            margin-left: -150px;
            width: auto;
    }
<div id ="footer" style="margin:auto;text-align:center;">
    <div id ="footer" align='center' >
       <div class="nails-footer-buttons">But01</div>
       <div class="nails-footer-buttons">But02</div>
       <div class="nails-footer-buttons">But03</div>
       <div class="nails-footer-buttons">But04</div>
    </div>