CSS3学习第四天

1、项目-对齐方式

弹性盒里边的小盒子叫项目

(1)例子1

效果:

 

代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 500px;
            height: 500px;
            border: 2px solid black;
            margin: 100px auto;
            display: flex;
        }
        .box div{
            width: 100px;
            /* height: 100px; */
            border: 1px dashed red;
            box-sizing: border-box;
        }
        .div1{
            height: 100px;
            align-self: flex-start;
        }
        .div2{
            height: 100px;
            align-self: flex-end;
        }
        .div3{
            height: 100px;
            align-self: center;
        }
        .div4{
            height: 100px;
            align-self: baseline;
        }
        .div5{
            align-self: stretch;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="div1">111</div>
        <div class="div2">222</div>
        <div class="div3">333</div>
        <div class="div4">444</div>
        <div class="div5">555</div>
    </div>
</body>
</html>

(2)例子2

效果:

代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 500px;
            height: 500px;
            border: 2px solid black;
            margin: 100px auto;
            display: flex;
            flex-direction: column;
        }
        .box div{
            /* width: 100px; */
            height: 100px;
            border: 1px dashed red;
            box-sizing: border-box;
          
        }
        .div1{

            align-self: flex-start;
        }
        .div2{
          
            align-self: flex-end;
        }
        .div3{
          
            align-self: center;
        }
        .div4{
          
            align-self: baseline;
        }
        .div5{
            align-self: stretch;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="div1">111</div>
        <div class="div2">222</div>
        <div class="div3">333</div>
        <div class="div4">444</div>
        <div class="div5">555</div>
    </div>
</body>
</html>

2、项目-调整顺序order

效果:

代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 500px;
            height: 500px;
            border: 2px solid black;
            margin: 100px auto;
            display: flex;
            flex-direction: row-reverse;
        }
        .box div{
            width: 100px;
            height: 100px;
            border: 1px dashed red;
            box-sizing: border-box;
          
        }
        .div3{
          /* 
          order默认值是0
          order值越大,越往后跑
          order值一样,按顺序来
           */
           order: 1;
        }
        .box4{
            order: 1;
        }
        .div5{
           order: -1;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="div1">111</div>
        <div class="div2">222</div>
        <div class="div3">333</div>
        <div class="div4">444</div>
        <div class="div5">555</div>
    </div>
</body>
</html>

3、项目-剩余宽高flex

(1)案例一

效果:

代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 500px;
            height: 500px;
            border: 2px solid black;
            margin: 0 auto;
            display: flex;
        }
        .box div{
            width: 100px;
            height: 100px;
            border: 1px dashed red;
        }
        .div1,.div3{
            flex: 1;
        }
        .div2{
            /* 占满剩余空间 */
            /* 分成六份,div2占5份大小 */
            flex: 5;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="div1"></div>
        <div class="div2"></div>
        <div class="div3"></div>
    </div>
</body>
</html>

(2)案例二

效果:

代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0%;
            padding: 0%;
        }
        html,body{
            height: 100%;
        }
        body{
            display: flex;
        }
        .box1,.box3{
            /* 注意根据需求只设宽度或高度 */
            width: 100px;
            background: grey;
        }
        .box2{
            flex: 1;
            background: yellow;
        }
    </style>
</head>
<body>
    <div class="box1"></div>
    <div class="box2"></div>
    <div class="box3"></div>
</body>
</html>

(3)案例三

效果:

代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0%;
            padding: 0%;
        }
        html,body{
            height: 100%;
        }
        body{
            display: flex;
            flex-direction: column;
        }
        .box1,.box3{
            /* 注意根据需求只设宽度或高度 */
            height: 100px;
            background: grey;
        }
        .box2{
            flex: 1;
            background: yellow;
        }
    </style>
</head>
<body>
    <div class="box1"></div>
    <div class="box2"></div>
    <div class="box3"></div>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值