首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 ><center>的替代

<center>的替代
EN

Stack Overflow用户
提问于 2009-12-18 07:33:53
回答 5查看 11.5K关注 0票数 7

我一直认为用<center>替换<div style="text-align:center;">标记会得到同样的结果。显然我错了。

这是我的HTML:(您还可以在我为这个问题创建的页面:http://www.catmoviez.com/ErrorPageSO.aspx中看到它的一部分)。

代码语言:javascript
复制
<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>

我想做两件事:

  1. 去掉<center>标记,同时将div保持在页面的中心。
  2. 确保外部DIVs背景色和边框影响内部跨度。

更新:目标1已经完成。实现目标2.的时间

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2009-12-18 07:38:08

在随附的margin: 0 auto;上使用<div>

代码语言:javascript
复制
<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:以事物为中心

票数 10
EN

Stack Overflow用户

发布于 2009-12-18 07:52:52

如果您想简单地对文本进行居中,请使用以下css样式:

代码语言:javascript
复制
text-align:center;

但是,如果您希望将元素或div本身作为中心,有相当多的解决方案,其中之一如下:

代码语言:javascript
复制
.mydiv
{
  margin:0 auto;
}

甚至像这样的事情:

代码语言:javascript
复制
.mydiv
{
  width:300px; // the width can sometimes be ignored based on inherent size of element.
  margin-left:auto;
  margin-right:auto;
}

甚至像这样的事情:

代码语言:javascript
复制
.mydiv
{
  margin-left:50%;
  margin-right:50%;
}

所以你看,可能有更多的可能性。

票数 6
EN

Stack Overflow用户

发布于 2009-12-18 07:39:12

内联内容与文本对齐,块内容与边距对齐(在居中情况下设置为auto )。见使用CSS对心

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1926864

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档