0

内部に「位置」スタイルとコンテンツを持つ 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;

4

1 に答える 1

1

絶対位置がある場合は、次を使用します: パディングを含めて要素の幅の半分にleft: 50%; margin-left: -200px変更します。200px

于 2013-01-18T16:33:11.743 に答える