CSS 定位 - 将 div 调整为其他 div

标签 css

<div id="container" style="width:300px;">
   <div id="leftBar" style="display: inline-block; width: 200px;">
       //explanding text ... bla bla bla
   </div>
   <div id="rightBar" style="display: inline-block; width: 100px;">
       //this bar has a background image that should stretch to a the left bars HEIGHT
   </div>
</div>

我希望 rightBar 与 leftBar 一起扩展。我不能使用固定值,因为 leftBar 包含长度不同的文本。 rightBar 的高度应与 leftBar 的高度相等。

最佳答案

您可以稍微更改标记并以这个 HTML 结束:

<div id="container">
    <div id="leftBar">
        <div id="rightBar">
            This is your 'rightBar'
        </div>
        <p>Many paragraphs of text</p>
        <p>Many paragraphs of text</p>
        <p>Many paragraphs of text</p>
        <p>Many paragraphs of text</p>
        <p>Many paragraphs of text</p>
        <p>Many paragraphs of text</p>
        <p>Many paragraphs of text</p>       
        <p>Many paragraphs of text</p>
        <p>Many paragraphs of text</p>
        <p>Many paragraphs of text</p>
    </div>
</div>​​​

和这个 CSS:

#container {
    width: 300px;
    background-color: yellow;
    overflow: hidden;
}

#leftBar {
    position: relative;
    width: 200px;
    background-color: green;
    padding-right: 100px;
}

#rightBar {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 100px;
    background-color: red;
    *height: expression(document.getElementById('container').offsetHeight); /*ie6 hack*/
}

这应该可以完美运行。 Check it out.

关于CSS 定位 - 将 div 调整为其他 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3765127/

相关文章:

css - 无限闪烁的 CSS3 动画

css - GSAP 笔划动画 strokeDashoffset 无法正常工作

android - 防止点击默认的蓝色选择

html - 标题在居中对齐段落的左侧对齐

php - 主页 wordpress 中的 2 列

python - CSS/Xpath 选择器,用于具有特定类的元素,其中包含具有特定文本的元素

html - CSS使表格自动从thead变成一列标签

css - 未应用 IE 11 CSS

CSS 错误仅在使用 chrome 刷新时

javascript - mcustomscrollbar 并滚动到相应的部分