【问题标题】:height of div doesn't go along with content next to itdiv 的高度与它旁边的内容不符
【发布时间】:2013-03-01 21:24:16
【问题描述】:

我会解释我的问题:

我有一个内容 div,其中包含 3 个其他 div:

                #content
#menu            #text          #sidebar
..          text...........      ------
..          text...........      ------
..          text...........      ------
            text...........      ------
            text...........
            text...........

这就是它的样子,#sidebar 中的条纹显示其中的内容。 侧边栏有一个绿色背景,该颜色贯穿整个网站。

但我想要的是#sidebar 的长度与#text 的长度相同。它应该看起来像这样:

                #content
#menu            #text          #sidebar
..          text...........      ------
..          text...........      ------
..          text...........      ------
            text...........      ------
            text...........      ------     
            text...........      ------

我不是专业的程序员,所以希望有人能帮助我。我已经尝试了一些“合乎逻辑”的事情,例如: -将#sidebar的高度设置为自动 - 将#sidebar 的高度设置为 100%(只会让它变长一点)

希望有人可以帮助我!提前致谢。

【问题讨论】:

  • 这是网站:colinch.com/52
  • 你试过搜索“css 等高列”吗?

标签: css html height


【解决方案1】:

如果您在内容 div 上定义一个高度,并为每个树指定应该执行此操作的 style="height:inherit" :)

【讨论】:

  • 这需要一个固定的高度或在页面完成加载时设置高度的 JavaScript 解决方案。
  • 这行得通,但另一个答案给出了一个解决方案,您不必在内容 div 上定义高度;)
【解决方案2】:

尝试以下更改:

#content {
    position: relative;
}

#balk {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
}
#balkgroen {
    height: 100%;
}

然后您可以删除#balk#balkgroen 上的float 以及#balk 上的margin

【讨论】:

  • 哇,非常感谢它的工作!这个比另一个答案更好,因为现在我不必为#content 设置高度,一切都会自动改变!我还不能投票给你的答案,但非常感谢
  • 当#content 比#balk 短时会发生什么?除非绝对必要,否则应避免绝对定位。
猜你喜欢
  • 2019-01-18
  • 1970-01-01
  • 1970-01-01
  • 2021-06-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多