Safari浏览器中的中心元素

时间:2013-06-08 09:10:03

标签: html css safari center centering

我有一个简单的页面:

<!DOCTYPE html><html><head><title>Choose your Location - ChubbyParade.com</title>
<style type="text/css">
#sv_btn_container{
    display:block;
    text-align:center;
    margin:0px auto;
}
#sbm_btn{
    margin-left:auto;
    margin-right:auto;
}
#location_selector{text-align:center;}
</style>
</head>
<body>

<div id="location_selector" style="width:300px;padding:1em;margin:0;border:1px solid #999999">
<form>
    <div>Please choose your location</div>

    <div id="selectors">
        <div>
            <select name="country" style="padding:0.5em">
                <option>Country</option>
                <!--etc.-->
            </select>
        </div>
    </div>
    <div style="clear:both"></div>

    <div id="sv_btn_container" style="margin-top:0.5em" align="center">
        <input type="submit" id="sbm_btn" value=" SAVE " class="button" style="display:none" />
    </div>
</form>
</div>

</body></html>

我使用javascript动态显示提交按钮,方法是将其显示样式设置为“阻止”(上面的脚本中未显示)。

我希望提交按钮居中。

但无论我尝试过哪种自动边距和文字对齐组合,按钮都会显示在其容器的左侧。

2 个答案:

答案 0 :(得分:3)

按钮需要设置宽度:

#sbm_btn{
    width: 200px;
    margin-left:auto;
    margin-right:auto;
}

如果你没有为btn设置宽度,你会这样做:

#sbm_btn {
   display:inline-block;
}

其他methods

答案 1 :(得分:2)

设置提交按钮的宽度,例如:

#sbm_btn{
margin-left:auto;
margin-right:auto;
width:100px;
height:30px;

}