【问题标题】:Two columns don't fit in container with vertical scrollbar两列不适合带有垂直滚动条的容器
【发布时间】:2012-07-07 01:22:33
【问题描述】:

我有一个两列布局,它在调整以摆脱身体上的双滚动条时停止工作。现在我在 wrap 上有一个滚动条,这是我想要的,但内容不知何故与滚动条的宽度重叠。

html, body {
  margin:0;
  padding:0;
  font: 12px Geneva, Verdana, sans-serif;
  color: #1e1f21;
  vertical-align: top;
  height: 100%
}

body {
  background: #fff url(../esimages/cubes.png) no-repeat left bottom fixed;
}

#wrap {
  background: #f5f5f5;
  margin: 0 auto;
  width: 960px;
  height: 100%;
}

#logo {
  height: 75px;
  width: 100%;
  background: #1e1f21;
  padding: 10px 0px 5px 0px;
}

#header {
  height: 30px;
  width: 100%;
  background: #1e1f21;
  margin:0px;
  padding: 0px;
}

#container {
  overflow: hidden;
  height: auto;
  background: #f5f5f5;
  width: 100%;
  margin: 0px;
  padding: 0px;
  text-align: left;
}

#content1 {
  min-height: 100%;
  background: #f5f5f5;
  padding: 20px 20px 20px 40px;
  margin: 0
}

#content2 {
  float: right;
  width: 290px;
  min-height: 100%;
  background: #f5f5f5;
  padding: 20px 0px 20px 10px;
  margin: 0
}

#footer {
  clear: both;
  padding: 10px;
  background: #1e1f21;
  text-align: center;
  line-height: 200%;
  font-size: 10px;
}

这两个内容框无法按应有的方式并排放入容器中。我已经尝试为 content1 使用不同的缩小固定宽度,但它根本没有区别,并且列宽无论如何都保持不变。我把头发扯掉了,因为这不合逻辑!

<body>
  <div id="wrap">
    <div id="logo"></div>
    <div id="header"></div>
    <div id="container">
      <div id="content2">
        <div class="box0">
          <ul>
            <li></li>
          </ul>
        </div>
      </div>
      <div id="content1">
        <p></p>
      </div>
    </div> 

<div id="footer" align="center"></div>

【问题讨论】:

  • 你能发布html吗?
  • 对不起,不擅长贴代码...
  • 对不起,我很愚蠢,但我怎样才能发布 html?它不允许我复制和粘贴。
  • @DavidAleu
  • 您必须编辑您的问题...我已经为您完成了

标签: html css two-column-layout


【解决方案1】:

您需要在content1 上添加一个宽度和float: left。还要记住,总宽度 + 填充不能超过容器的宽度。

另外,margin: 0 后面缺少一个分号来表示content1

【讨论】:

  • 分号是我的错字。它在我的 CSS 中。我确实在 content1 上有 float:left 和固定宽度,但在某处读到最好将它们都消除,这样它就会自行调整到可用的宽度。反正没区别。
  • 已经回到在 html 上而不是在 wrap 上使用滚动条并解决了问题。但是,如果有人知道如何将滚动条放在包装或容器上而不影响其宽度,我希望你能告诉我如何做到这一点。谢谢。
猜你喜欢
相关资源
最近更新 更多
热门标签