如何将具有“位置”风格和内容的div集中在里面?

时间:2013-01-18 16:31:00

标签: css css3

如何将具有“位置”风格和内容的div居中?我有下一个代码:

<div class="block" id="block1" style="position:relative;">
    <img />

    <div id="temperature" style="position:absolute; top:50px; min-width: 400px; height: 300px; margin: 0 auto"></div>

    <div id="tempeControl" style="position:absolute; bottom:0; ">   
        <button id="minus" style="height: 28px; width:128px;">-</button>
        <span id="valueTempe" style="font-weight: bold; color: #fea100; width:28px;">0</span>
        <button id="plus" style="height: 28px; width:128px;">+</button> 
    </div>              
</div>

我尝试使用<center>text-align:center(我认为相同),margin-left:auto; margin-right:auto;

1 个答案:

答案 0 :(得分:1)

如果您有绝对位置,请使用以下内容: left: 50%; margin-left: -200px200px更改为元素宽度的一半,包括填充。