CSS的flex常用布局

CSS的flex左边固定右边自适应例子

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>css flex 左边固定右边自适应例子</title>
    <style>
        body {
            padding: 5px
        }
        #boxs {
            width: 80%;
            height: 100px;
            border: 1px solid #333;
            display: flex;
        }
        .left {
            width: 200px;
        }
        .right {
            flex: 1;
            /*
            flex-grow:1;
            flex-shrink:1;
            */
        }
    </style>
</head>
<body>
<div id="boxs">
    <div class="left" style="background-color:#ffc5c5;">左边固定宽度</div>
    <div class="right" style="background-color:#7171f7;">右边自适应宽度</div>
</div>
</body>
</html>

结果
在这里插入图片描述

CSS的flex左边自适应右边固定例子

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>css flex 左边自适应右边固定例子</title>
    <style>
        body {
            padding: 5px
        }
        #boxs {
            width: 80%;
            height: 100px;
            border: 1px solid #333;
            display: flex;
        }
        .left {
            flex: 1;
            /*
            flex-grow:1;
            flex-shrink:1;
            */
        }
        .right {
            width: 200px;
        }
    </style>
</head>
<body>
<div id="boxs">
    <div class="left" style="background-color:#ffc5c5;">左边自适应宽度</div>
    <div class="right" style="background-color:#7171f7;">右边固定宽度</div>
</div>
</body>
</html>

结果
在这里插入图片描述

CSS的flex两边固定中间自适应例子

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>css flex 两边固定中间自适应例子</title>
    <style>
        body {
            padding: 5px
        }
        #boxs {
            width: 90%;
            height: 100px;
            border: 1px solid #333;
            display: flex;
        }
        .dwidth {
            width: 150px;
        }
        .center {
            flex: 1;
        }
    </style>
</head>
<body>
<div id="boxs">
    <div class="dwidth" style="background-color:#ffc5c5;">左边固定宽度</div>
    <div class="center" style="background-color:#b9f;">中间自适应宽度</div>
    <div class="dwidth" style="background-color:#7171f7;">右边固定宽度</div>
</div>
</body>
</html>

结果
在这里插入图片描述

CSS的flex上下固定中间自适应例子

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>css flex 上下固定中间自适应例子</title>
    <style>
        body {
            padding: 5px
        }
        #boxs {
            width: 90%;
            height: 300px;
            border: 1px solid #333;
            display: flex;
            flex-direction: column
        }
        .dheight {

            height: 50px;
        }
        .center {
            flex: 1;

        }
    </style>
</head>
<body>
<div id="boxs">
    <div class="dheight" style="background-color:#ffc5c5;">上边固定宽度</div>
    <div class="center" style="background-color:#b9f;">中间自适应宽度</div>
    <div class="dheight" style="background-color:#7171f7;">下边固定宽度</div>
</div>
</body>
</html>

结果
在这里插入图片描述

CSS的flex单行省略号

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>css flex 1 单行省略号</title>
    <style>
        body {
            padding: 5px
        }
        #boxs {
            width: 80%;
            height: 100px;
            border: 1px solid #333;
            display: flex;
        }
        .left {
            width: 200px;
        }
        .right {
            flex: 1;
            min-width: 0;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
</head>
<body>
<div id="boxs">
    <div class="left" style="background-color:#ffc5c5;">左边固定宽度</div>
    <div class="right" style="background-color:#7171f7;">
        右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度
    </div>
</div>
</body>
</html>

结果
在这里插入图片描述

CSS的flex多行省略号

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>css flex 多行文本省略号</title>
    <style>
        body {
            padding: 5px
        }
        #boxs {
            width: 80%;
            height: 84px;
            border: 1px solid #333;
            display: flex;
        }
        .left {
            width: 200px;
        }
        .right {
            flex: 1;
            max-height: 84px;
            display: -webkit-box;
            -webkit-line-clamp: 4;
            -webkit-box-orient: vertical;
            overflow: hidden;
        }
    </style>
</head>
<body>
<div id="boxs">
    <div class="left" style="background-color:#ffc5c5;">左边固定宽度</div>
    <div class="right" style="background-color:#7171f7;">
        右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度右边自适应宽度
    </div>
</div>
</body>
</html>

结果
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

码上暴富

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

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

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

打赏作者

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

抵扣说明:

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

余额充值