我一直认为用<center>替换<div style="text-align:center;">标记会得到同样的结果。显然我错了。
这是我的HTML:(您还可以在我为这个问题创建的页面:http://www.catmoviez.com/ErrorPageSO.aspx中看到它的一部分)。
<div style="margin: 0 auto; background-color:red;border:5px solid black;margin-top:5px;width:750px;text-align:center;">
<span style="width:560px;padding-right:10px;text-align:left;float:left;">
<h1>Oops... We're sorry.</h1>
<h3>You've just encountered an unknown error. <br /></h3>
This site is a work-in-progress, we have already been informed of the error and will do our best to fix it. <br />
We would be thankful if you could contact us through the appropriate button and elaborate on what caused this error to appear.<br />
<br />
<h3>
You can go back to the <a style="text-decoration:underline;" href="Default.aspx">Home page</a> and continue using Moviez.NET.
</h3>
</span><span style="width:180px;float:left;"><img src="Resources/Images/404.jpg" /></span>
</div>我想做两件事:
<center>标记,同时将div保持在页面的中心。更新:目标1已经完成。实现目标2.的时间
发布于 2009-12-18 07:38:08
在随附的margin: 0 auto;上使用<div>
<div style="margin: 0 auto; background-color:red;border:5px solid black;margin-top:5px;width:750px;text-align:center;">
<span style="width:560px;padding-right:10px;text-align:left;">
<h1>Oops... We're sorry.</h1>
<h3>You've just encountered an unknown error. <br /></h3>
This site is a work-in-progress, we have already been informed of the error and will do our best to fix it. <br />
We would be thankful if you could contact us through the appropriate button and elaborate on what caused this error to appear.<br />
<br />
<h3>
You can go back to the <a style="text-decoration:underline;" href="Default.aspx">Home page</a> and continue using Moviez.NET.
</h3>
</span><span style="width:180px;"><img src="Resources/Images/404.jpg" /></span>
</div>看到它的行动。
参考资料:CSS:以事物为中心
发布于 2009-12-18 07:52:52
如果您想简单地对文本进行居中,请使用以下css样式:
text-align:center;但是,如果您希望将元素或div本身作为中心,有相当多的解决方案,其中之一如下:
.mydiv
{
margin:0 auto;
}甚至像这样的事情:
.mydiv
{
width:300px; // the width can sometimes be ignored based on inherent size of element.
margin-left:auto;
margin-right:auto;
}甚至像这样的事情:
.mydiv
{
margin-left:50%;
margin-right:50%;
}所以你看,可能有更多的可能性。
发布于 2009-12-18 07:39:12
内联内容与文本对齐,块内容与边距对齐(在居中情况下设置为auto )。见使用CSS对心。
https://stackoverflow.com/questions/1926864
复制相似问题