后端的前端笔记:flex布局

1、flex布局原理

在这里插入图片描述

在这里插入图片描述

2、flex布局父项常见属性

常见父项属性

在这里插入图片描述

1)flex-direction设置主轴的方向

主轴与侧轴

在这里插入图片描述

在这里插入图片描述

2)justify-content设置主轴上的子元素排列方式

在这里插入图片描述

3)flex-wrap子元素是否换行

在这里插入图片描述

4)align-items设置侧轴上的子元素排列方式(单行)

在这里插入图片描述

5)align-content设置侧轴上的子元素的排列方式(多行)

在这里插入图片描述

align-content和align-items的区别

在这里插入图片描述

6)flex-flow

在这里插入图片描述

7)小结

在这里插入图片描述

3、flex布局子项常见属性

1)flex子项目占的份数

在这里插入图片描述

案例

<html>

<head>
    <style>
        section {
     
     
            display: flex;
            width: 60%;
            height: 150px;
            margin: 0 auto;
        }

        section div:nth-child(1) {
     
     
            width: 100px;
            height: 150px;
            background-color: red;
        }

        section div:nth-child(2) {
     
     
            flex: 1;
            background: green;
        }

        section div:nth-child(3) {
     
     
            width: 100px;
            height: 150px;
            background-color: blue;
        }

        p {
     
     
            display: flex;
            width: 60%;
            height: 150px;
            background-color: pink;
            margin: 100px auto;
        }

        p span {
     
     
            flex: 1;
        }

        p span:nth-child(2) {
     
     
            flex: 2;
            background-color: purple;
        }
    </style>
</head>

<body>
    <section>
        <div></div>
        <div></div>
        <div></div>
    </section>

    <p>
        <span>1</span>
        <span>2</span>
        <span>3</span>
    </p>
</body>

</html>

在这里插入图片描述

2)align-self控制子项自己在侧轴的排列方式

在这里插入图片描述

3)order属性定义子项的排列顺序(前后顺序)

在这里插入图片描述

学习资料

https://www.bilibili.com/video/BV1N54y1i7dG?p=3

猜你喜欢

转载自blog.csdn.net/qq_40378034/article/details/110728985