【问题标题】:100% height column with fixed sidebar100% 高度列,固定侧边栏
【发布时间】:2013-03-16 18:27:38
【问题描述】:

我一直在努力让它发挥作用。当主列的内容填满页面高度时它看起来正确,但当它没有填满时则不正确。

看起来不错:http://jsfiddle.net/creativetags/ngv4H/1/

看起来不对:http://jsfiddle.net/creativetags/EAuBc/1/

<div class='container'>
    <div class='container-wrap'>
        <nav class='tabnav'>Some nav menu items here</nav>
        <div class='container-inner'>
            <div class='clearfix' id='mainwrap'>
                <div class='columns' id='main'>
                     <h2>Main content scrolls here</h2>
                </div>
            </div>
            <div class='columns' id='side'>
                <div class="sidecontent">
                    <p>Fixed Side panel</p>
                </div>
            </div>
        </div>
    </div>
</div>

我使用的是固定的人造侧边栏列,因此当您滚动主列时,它会保持在视图中。

我需要.container-inner 的背景填充到页面底部,即使内容没有到达底部。

.tabnav需要从body标签显示背景图片,所以.container-inner不能从页面顶部开始。

【问题讨论】:

    标签: html css layout two-columns


    【解决方案1】:

    使用相同的 CSS 更新了 large contentsmall content 的演示。

    变更摘要

    修复主要内容

    • 将白色背景颜色应用于.container-wrap.container-inner
    • .container.container-wrap 设置为height:100%;
    • .tabnav 下面的背景图像现在被白色背景颜色覆盖,因此将背景图像重新应用到.tabnav这是解决方案的关键部分

    更新侧边栏

    • #side.sidecontent 设置为height:100%;
    • 将侧面背景图片从.container 移动到.sidecontent

    添加了 CSS

    .container {
        height: 100%;
        ...
    }
    .container-wrap {
        width: 660px;
        height: 100%;
        background-color: #f8f8f8;
    }
    .tabnav {
        background: #1d1d1b url("http://cat.storehousebelfast.com/assets/bg.jpg") repeat fixed top left;
    }
    #side {
        height: 100%;
        ...
    }
    .sidecontent {
        background: transparent url("http://cat.storehousebelfast.com/assets/right-column.gif") repeat-y top right;
        height: 100%;
        ...
    }
    

    已移除 CSS

    .container {
        background: transparent url("http://cat.storehousebelfast.com/assets/right-column.gif") repeat-y top right;   /* Remove this */
        ...
    }
    .container-inner {
        min-height: 100%;   /* Remove this */
        height: 100%;       /* Remove this */
        ...
    }
    

    【讨论】:

    • 谢谢@Matt。这是一个合理的解决方案 - 非常有据可查的更改!