Force align a content in center

一曲冷凌霜 提交于 2019-12-07 02:48:30

问题


I have some content which will contain some divisions, labels, forms in it. I want to force them in the center of page. How can I do this?

Note: I tried using <div align="center">, <center> but nothing works?


回答1:


If your content doesn't have a fixed width do this:

<div class="content">
 <div class="inner">some content</div>
</div>


.content
{
 text-align: center;
}
.inner
{
 display:inline-block;
}

If it does, you could do this:

.content
{
 width: xpx;
 margin: 0 auto;
}



回答2:


You must use margin (auto) to center the div but it must have a width.

W3School - Center Aligning Using the margin Property




回答3:


<div style="text-align: center;">testing text align</div> 



回答4:


Try this:

div {
    margin:0 auto;
}


来源:https://stackoverflow.com/questions/17785752/force-align-a-content-in-center

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!