当前位置:网站首页>Three implementation methods: left fixed and right adaptive (Flex, float + BFC, float margin left)

Three implementation methods: left fixed and right adaptive (Flex, float + BFC, float margin left)

2022-06-23 05:24:00 PHP code

// structure 
<div class="demo">
    <div class="left"></div>
    <div class="right"></div>
</div>

1.Flex

<style>
    * {
        padding: 0;
        margin: 0;
    }

    .demo {
        overflow: hidden;
        display: flex;
    }

    .left {
        width: 200px;
        height: 200px;
        background-color: red;
    }
    .right{
        height: 200px;
        background-color: aquamarine;
        flex: 1;
    }
</style>

2.float + BFC 

<style>
    * {
        padding: 0;
        margin: 0;
    }

    .demo {
        overflow: hidden;

    }

    .left {
        width: 200px;
        height: 200px;
        background-color: red;
        float: left;
    }

    .right {
        height: 200px;
        background-color: aquamarine;
        /*  formation BFC The box  */
        overflow: auto;
    }
</style>

 3.float + margin-left

<style>
    * {
        padding: 0;
        margin: 0;
    }

    .demo {
        /*  Remove the floating  */
        overflow: hidden;

    }

    .left {
        width: 200px;
        height: 200px;
        background-color: red;
        float: left;
    }

    .right {
        height: 200px;
        background-color: aquamarine;
        /*  Fixed box width  */
        margin-left: 200px;
    }
</style>

原网站

版权声明
本文为[PHP code]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230308139275.html