开发者

How to align a div in the center of a HTML page?

开发者 https://www.devze.com 2022-12-11 03:11 出处:网络
I\'ve to align some text in the center of the page wit开发者_开发技巧h div tag.div#foo { text-align:center; }

I've to align some text in the center of the page wit开发者_开发技巧h div tag.


div#foo { text-align:center; }

to align the text within the div or

div#foo { width:100px; margin:0 auto; }

to make the div 100px width and horizontally center it.


You could set the style of the div to be:

<div style="width: 250px; margin-left:auto; margin-right:auto;">TEXT</div>

You can also place that style in a CSS class and set the class of the div to whatever you named it.

EDIT: If you include a width for the div, it centers...


You can try <div align="center">...</div>


Simply use the following styling:

div {margin:0 auto;}
0

精彩评论

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