码迷,mamicode.com
首页 > Web开发 > 详细

CSS两列布局

时间:2019-09-01 18:34:03      阅读:83      评论:0      收藏:0      [点我收藏+]

标签:技术   float   适应   宽度   pos   play   htm   red   round   

方法1:左边设置绝对定位,右边设置左外边距,大小和左边的宽度相等

//CSS部分:
        .contain{
            position :relative;
            height: 300px;
        }

        .left{
            position: absolute;
            left: 0;
            top: 0;

            width: 200px;
            height: 300px;
            background: red;
        }
        .right{
            /*使用左外边距*/
            margin-left: 200px;
            height: 300px;
            background: blue;
        }

//html部分:
<div class="contain">
     <div class="left">左边定宽</div>
     <div class="right">右边自适应</div>
 </div>
方法2:左边设置左浮动,右边隐藏溢出的内容
.contain{
position :relative;
height: 300px;
}
.left{
float: left;
width: 300px;
height: 300px;
background:red;
}
.right{
overflow: hidden;
background: blue;
height: 300px;
}

<div class="contain">
     <div class="left">左边定宽</div>
     <div class="right">右边自适应</div>
 </div>
方法3:弹性布局
.contain{
   display: flex;
}
.left{
    width: 200px;
    height: 200px;
    background: red;
}
.right{
    flex: 1;
    height: 200px;
    background:blue;
}

方法4:左右都设置浮动,width:calc()
.contain {
    position: absolute;
    width: 100%;
    height: 100%;
}
.left {
    float: left;
    width: 200px;
    height: 100%;
    background-color: #72e4a0;
}
.right {
    float: left;
    width: calc(100% - 200px);
    height: 100%;
    background-color: #9dc3e6;
}

最终结果:

技术图片

 

CSS两列布局

标签:技术   float   适应   宽度   pos   play   htm   red   round   

原文地址:https://www.cnblogs.com/qing-5/p/11442906.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!