Force align a content in center

核能气质少年 提交于 2019-12-05 08:21:58

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;
}
Done

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

W3School - Center Aligning Using the margin Property

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

Try this:

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