首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么我的两列在IE7中不能正确对齐?

为什么我的两列在IE7中不能正确对齐?
EN

Stack Overflow用户
提问于 2009-05-14 15:35:34
回答 2查看 1.4K关注 0票数 5

我通过书籍和网站自学CSS。我已经创建了一个简单的站点,它有一个居中的框,后面跟着两列,它在Firefox3和Safari3中显示得很好,但在IE7中就不行了。我的右列保持在右边,但被向下推,这样它就从左列结束的地方开始。我看过很多关于IE黑客的博客,但我不知道应该应用哪个,或者应该在我的代码中添加它。任何建议都将不胜感激!

这是我的CSS:

代码语言:javascript
复制
#wrapper {
position:relative;
width:900px;
margin-right:auto;
margin-left:auto;
}

#centerbox {
background-color:#FFFFFF;
width:870px;
margin-left:auto;
margin-right:auto;
padding:10px 15px 10px 15px;
margin-bottom:30px;
text-align:left;
border:8px solid #E0BB24;
}

#leftcolumn {
float:left;
margin-left:10px;
width:410px;
padding:0px 10px 10px 10px;
color:#FFFFFF;
}

#rightcolumn {
width:395px;
margin-left:480px;
margin-right:10px;
padding:0px 15px 10px 10px;
background-color:#FFFFFF;
border:1px solid #26A9E0;
}

这是我的HTML:

代码语言:javascript
复制
<div id="centerbox" class="clear">
<h1>The physician's creed: &quot;First, do no harm&quot;</h1>
<h3>Politicians, policymakers, and public officials should take the same oauth</h3>
<p>Text</p>
</div>

<div id="leftcolumn">
<h2><img src="images/accept.png" alt="Putting Patients First" align="left"> </img>Putting Patients First</h2>
<p class="spaceafter"><a href="betterway.html">Read more about our idea of a better way to reform health care by putting patients first &raquo;</a></p>

<h2><img src="images/reject.png" alt="Principles for reform" align="left"></img>Principles for reform</h2>
<p class="spaceafter">Tell politicians in Washington you will follow these <a href="donoharm.html">principles</a> in judging any health reform proposal:</p>
<ul>
    <li>No new government-run health insurance plan</li>
    <li>No one-size government-dictated package of health benefits</li>
    <li>No new jobs-killing mandates on employers</li>
    <li>No requirement on individuals to buy this expensive coverage</li>
    <li>No federal institution that controls private health insurance</li>
    <li>No government intrusion into our medical privacy</li>
    <li>No federal government control over the practice of medicine through a federal health board, comparative effectiveness review, and other government intrusions into doctor-patient medical decision-making</li>
</ul>
<p><a href="donoharm.html">Read more &raquo;</a></p>
</div>

<div id="rightcolumn">
<h2><img src="images/signpetition.png" alt="Sign the petition" align="left">    </img>Sign the petition</h2>
<p>Dear Policymaker: I stand with millions of Americans who implore you to follow the Do No Harm principles &mdash; and do NOT destroy America's health care system!</p>
<iframe height="920px" width="400px" name="zoho-Do_No_Harm_Petition" frameborder="0" scrolling="auto" src="http://creator.zoho.com/galeninstitute/do-no-harm-petition/form-embed/Do_No_Harm_Petition/reAUnSRw7O3sfWaOssaxgN91NbXFRYWUEQ8AZ5v803j2bVG4OHpFAXkvuUuqDVX9zxfg5YMSfMD9TTeqds1OE1kbYQqSSmYbFh6Z/"></iframe>
</div>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2009-05-14 15:38:50

我认为您错过了# right列上的浮动

代码语言:javascript
复制
#rightcolumn {
     float: right;
}

您还可以从#rightcolumn中删除这些值。

代码语言:javascript
复制
margin-left:480px;
margin-right:10px; 
票数 5
EN

Stack Overflow用户

发布于 2009-05-14 15:43:16

这就是我对三列div所做的(左、中、右都是div)

这三个像素都是310px,中间是10px (总共950px),你可以根据你的尺寸进行调整。

诀窍在于中间的div,它基本上占据了整个“row”的空间,但有足够的填充来清除位于中间div顶部的“浮动”的左右div的内容。

代码语言:javascript
复制
#left
{
    float: left;
    width: 310px;
}

#middle
{
    padding: 0px 320px 5px 320px;
}

#right
{
    float: right;
    width: 310px;
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/864081

复制
相关文章

相似问题

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