流式布局-两栏布局

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        /* 1.利用bfc块级格式化上下文, 实现左侧固定右侧自适应
        (1) 让左边的盒子 float: left;
        (2) 让右边的盒子 overflow: hidden; */
        
        * {
            margin: 0;
            padding: 0;
        }
        
        p {
            width: 80%;
            margin: 20px auto;
            background-color: beige;
        }
        
        .father {
            height: 400px;
            background-color: rgb(84, 107, 128);
        }
        
        .left {
            height: 400px;
            width: 200px;
            float: left;
            background-color: red;
        }
        
        .right {
            height: 400px;
            background-color: blueviolet;
            /* 触发了bfc的盒子, 不与浮动的元素重叠 */
            overflow: hidden;
        }
        /* 2.利用定位实现左侧固定右侧自适应
        (1) 给父盒子设置padding-left 值
        (2) 给左侧子盒子设置width = padding-left ,并定位到父盒子的padding-left上.
        (3) 右侧盒子自适应 */
        
        .father2 {
            height: 300px;
            background-color: rgb(68, 44, 44);
            position: relative;
            /* 给父级设置paddig-left值!!!!!!!!!!!!!! */
            padding-left: 150px;
        }
        
        .left2 {
            position: absolute;
            left: 0;
            width: 150px;
            height: 300px;
            background-color: yellowgreen;
        }
        
        .right2 {
            height: 300px;
            background-color: red;
        }
        /* 3.利用flex布局 实现左侧固定右侧自适应
        (1) 给父盒子设置display:flex ;
        (2) 左侧盒子设置固定宽高 ,右侧盒子设置flex:1 ; */
        
        .father3 {
            height: 300px;
            background-color: rgb(255, 119, 119);
            display: flex;
        }
        
        .left3 {
            width: 200px;
            height: 300px;
            background-color: red;
        }
        
        .right3 {
            height: 300px;
            background-color: pink;
            flex: 1;
        }
        /* // */
        /* 右侧固定,左侧自适应 
        1.BCF:右侧:float:right,左侧:overfow:hidden
        此时的右侧要写在左侧的前面*/
        
        .father1 {
            height: 400px;
            background-color: rgb(40, 64, 85);
        }
        
        .left1 {
            height: 400px;
            background-color: aqua;
            /* 触发bfc */
            overflow: hidden;
        }
        
        .right1 {
            height: 400px;
            /* 让右侧盒子浮动到右边!!!!!!!!!!!!!! */
            float: right;
            width: 200px;
            background-color: crimson;
        }
        /* 2.利用flex布局 */
        
        .father4 {
            height: 100px;
            background-color: #fff;
            display: flex;
        }
        
        .right4 {
            width: 200px;
            height: 100px;
            background-color: bisque;
        }
        
        .left4 {
            height: 100px;
            flex: 1;
            background-color: brown;
        }
    </style>
</head>

<body>
    <h3>利用bfc块级格式化上下文:左侧固定,右侧自适应</h3>
    <div class="father">
        <div class="left">left</div>
        <div class="right">right</div>
    </div>
    <h3>利用定位实现左侧固定右侧自适应</h3>
    <div class="father2">
        <div class="left2">left</div>
        <div class="right2">right</div>
    </div>
    <h3>利用flex布局 实现左侧固定右侧自适应</h3>
    <div class="father3">
        <div class="left3">left</div>
        <div class="right3">right</div>
    </div>








    <h3>-----------------------------------------------------------------------------------------</h3>
    <h3>-----------------------------------------------------------------------------------------</h3>
    <h3>-----------------------------------------------------------------------------------------</h3>
    <h3>利用bfc块级格式化上下文:右侧固定,左侧自适应</h3>
    <div class="father1">
        <!-- 注意:此时的右侧盒子要写到左侧盒子的前面!!!!!!!!!! -->
        <div class="right1">right</div>
        <div class="left1">left</div>
    </div>
    <h3>利用flex布局 实现右侧固定左侧自适应</h3>
    <div class="father4">
        <div class="left4">left</div>
        <div class="right4">right</div>
    </div>





    <p>BFC 块级格式化上下文 Block Formatting Context: 页面上一个隔离的独立渲染区域 触发成为 BFC 盒子的特点: 触发了 BFC 的盒子, 就成为了页面上的一个隔离的独立容器, 容器里面的子元素不会在布局上影响到外面的元素 应用: 解决塌陷问题, 清除浮动 触发了BFC的普通盒子, 不会与浮动元素重叠 应用: 圣杯布局, 左侧固定右侧自适应 如何触发 BFC float: left; float: right; overflow的值不为visible。 display的值为inline-block、table-cell、table-caption
        position的值absolute, fixed</p>
</body>

</html>

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

1planet

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值