css方法实现一:均使用fixed.

body {
        margin: 0;
    }
    .header {
        width: 100%;
        height: 54px;
        position: fixed;
        border-bottom: 1px solid #e4e6e9;
        background: #ccc;
    }
    .sidebar {
        position: fixed;
        top: 54px;
        bottom: 0;
        left: 0;
        width: 300px;
        border-right: 1px solid #e4e6e9;
        background-color: #fff;
    }
    .content {
        position: fixed;
        top: 54px;
        right: 0;
        bottom: 0;
        left: 301px;
        overflow-y: auto;
        background-color: #fff;
    }

css方法实现一:利用calc

body {
     margin: 0;
     height: 100%;
 }
 .header {
     top: 0;
     width: 100%;
     height: 54px;
     position: fixed;
     border-bottom: 1px solid #e4e6e9;
     background: #ccc;
 }
 .main {
     margin-top: 54px;
     height: calc(100% - 54px);
 }
 .sidebar {
     position: fixed;
     top: 54px;
     bottom: 0;
     left: 0;
     width: 300px;
     border-right: 1px solid #e4e6e9;
     background: grey;
     background-color: #fff;
 }
 .content {
     padding-left: 301px;
     overflow-y: auto;
     background-color: #fff;
 }

css方法实现三:relative,fixed,absolute定位

body {
     margin: 0;
 }
 .header {
     position: relative;
     z-index: 1;
     height: 54px;
     border-bottom: 1px solid #e4e6e9;
     background: #ccc;
 }
 .sidebar {
     position: fixed;
     top: 54px;
     bottom: 0;
     left: 0;
     width: 320px;
     border-right: 1px solid #e4e6e9;
     background-color: #fff;
 }
 .content {
     position: absolute;
     top: 54px;
     right: 0;
     bottom: 0;
     left: 321px;
     overflow-y: auto;
     background-color: #fff;
 }

总结:position:absolute是相对于最近的祖先定位为relative、absolute、fixed中的任何一个进行定位,若没有这样的祖先则相对于body进行定位。position:absolute和position:fixed均脱离了标准流。

以上就是“css如何实现内容固定不动”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注创新互联行业资讯频道。


网页题目:css如何实现内容固定不动
URL标题:http://tjjierui.cn/article/jocshh.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP