前端css实现左边div固定宽度100px,右边div自适应布局

一个人想着一个人 提交于 2019-12-10 05:12:31

html结构:

<div id="container">
    <div id="left"></div>
    <div id="right"></div>
</div>

方法一:flex 布局

#container{
    width:100%;
    height:500px;
    display: flex
}
#left{
    width:100px;
    height:100%;
    background: yellow;
}
#right{
    height:100%;
    background: pink;
    flex: 1
}

方法二:浮动

#container{
    width:100%;
    height:500px;
}
#left{
    width:100px;
    height:100%;
    background: yellow;
    float: left;
}
#right{
    height:100%;
    background: pink;
    padding-left:100px;
}

方法三:BFC(块级格式化上下文)

#container{
    width:100%;
    height:500px;
}
#left{
    width:100px;
    height:100%;
    background: yellow;
    float: left;
}
#right{
    height:100%;
    background: pink;
    overflow:hidden;
}

方法四:calc

#container{
    width:100%;
    height:500px;
}
#left{
    width:100px;
    height:100%;
    float: left;
    background: yellow;
}
#right{
    width: calc(100% - 100px);
    height:100%;
    float: right;
    background: pink;
    overflow:hidden;
}

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!