2013-01-18 133 views
0

如何中心,具有內側「位置」的風格和內容的DIV?我有下面的代碼:如何中心,具有內側「位置」的風格和內容的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;

+0

我將避免''

乾脆標籤不管你在做什麼,因爲它已經過時了。 http://stackoverflow.com/questions/1798817/why-is-the-center-tag-deprecated-in-html – Jason

回答

1

當你有絕對的位置,使用以下命令: left: 50%; margin-left: -200px變化200px爲您的元素寬度的一半,包括填充。