开发者

Div position centering

I have need to position div with id="center_dv" on center of the div with id="wrapper_dv" and to div wrapper_dv be on center of body. How can I do it ?

 <body>
    <div id="wrapper_dv">
        <div id="center_dv">
            <p>some text<开发者_如何学编程/p>
        </div>
    </div>
 </body>


the most common way is to give the div a width, and to use margin-left and margin-right: auto

If your div is normally having top and bottom margin as 0, then it can be

#center_dv { width: 300px; margin: 0 auto }
#wrapper_dv { width: 600px; margin: 0 auto }

(Giving margin 1 length means apply it to all 4 sides, top, bottom, left and right. Giving margin 2 lengths means apply the 1st length to top and bottom, and the 2nd length to left and right.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜