【问题标题】:Center Align Content居中对齐内容
【发布时间】:2013-06-07 19:11:50
【问题描述】:

我的网页上有以下两列布局设置:

<div id="column1-wrap">
    <div id="column1">Column one content</div>
</div>
<div id="column2">
    Column two content
</div>
    <div id="clear"></div>

由以下 CSS 提供支持:

#column1-wrap {
    float: left;
    width: 1000px;}
#column1 {
    margin-right: 600px;}
#column2 {
    float: left;
    width: 600px;
    margin-left: -600px;}

我怎样才能把它放在我的网页上?

【问题讨论】:

标签: html alignment


【解决方案1】:

你可能会这样做: html

<div class="container">
   <div id="column1-wrap">
     <div id="column1">Column one content</div>
   </div>
   <div id="column2">
      Column two content
   </div>
</div><!--container-->

CSS

.container{
    border:1px solid blue;
    margin:0px auto;
    }

【讨论】:

  • 没问题。很高兴我能帮上忙!
【解决方案2】:

尝试添加

margin: 0 auto;

到 #column1-wrap 在 css 中

【讨论】:

  • margin: 0 auto; 仅在元素已定义宽度时有效
  • @Cruelcrome 刚刚注意到了。我的坏
【解决方案3】:

hi Div 有一个属性 align 以使内容居中

<div align:center>
</div>

或 将样式设置为margin:0px auto;

【讨论】:

  • 不要这样做。内联样式不被认为是好的做法,应该在 CSS 中进行对齐。另外,语法也是错误的。
猜你喜欢
  • 1970-01-01
  • 2016-08-15
  • 2018-12-14
  • 1970-01-01
  • 2023-02-23
  • 2023-04-05
  • 2019-04-07
  • 2014-02-18
  • 1970-01-01
相关资源
最近更新 更多