问题
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