使用伪类实现高度自适应
具体实现代码如下
html { min-height: 100%; position: relative; } .sidebar { float: left; position: static; padding-left: 0; padding-right: 0; } .sidebar:before { content: ""; display: block; width: inherit; position: absolute; top: 0; bottom: 0; z-index: -1; background-color: inherit; border-style: inherit; border-color: inherit; border-width: inherit; }
即可在页面不断变化时,左侧的sidebar高度自适应浏览器高度