Java复习打卡day46

2021/5/22 20:27:47

本文主要是介绍Java复习打卡day46,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

Java复习打卡day46

  • flex弹性布局
    • flex弹性布局的体验
    • flex-direction
    • justify-content
    • flex-wrap
    • align-items
    • align-content

flex弹性布局


flex弹性布局的体验

<!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>
        #obox{width: 100%;height: 300px;background-color: #222;
            display: flex;
            /* 水平居中 两端对齐 */
            justify-content: space-between;
            /* 垂直居中 */
            align-items: center;
        }
        #os{width: 200px;height: 200px;background-color: #fff;}
    </style>
</head>
<body>
    <h1>flex弹性布局的体验</h1>
    <div id="obox">
        <div id="os"></div>
        <div id="os"></div>
        <div id="os"></div>
        <div id="os"></div>
    </div>
</body>
</html>

flex-direction

<!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>
        #obox{width: 100%; height: 600px;background-color: aqua; border: 2px solid #222; 
            display: flex;
            /* flex-direction设置内容沿着坐标轴的方向排列 */
            /* 默认是row 水平自左向右延伸 */
            /* flex-direction: row; */
            /* 设置水平自右向左延伸 */
            /* flex-direction: row-reverse; */
            /* 垂直延伸 自上向下延伸*/
            /* flex-direction: column; */
            /* 自下向上延伸 */
                flex-direction: column-reverse;
        }
        #os{
            width: 100px;
            height: 100px;
            background-color: orange;
        }
    </style>
</head>
<body>
    <h1>flex弹性布局--flex-direction</h1>
    <div id="obox">
        <div id="os">1</div>
        <div id="os">2</div>
        <div id="os">3</div>
        <div id="os">4</div>
    </div>
</body>
</html>

justify-content

<!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>
        #obox{
            width: 100%;
            height: 600px;
            background-color: aqua;
            border: 2px solid #222;
            /* 容器 */
            display: flex;
            /* justify-content设置元素在主轴上的排列方式 */
            /* 首部对齐 */
            justify-content: flex-start;
            /* 尾部对齐 */
            justify-content: flex-end;
            /* 居中对齐 */
            justify-content: center ;
            /* 平分水平空间对齐 */
            justify-content: space-around;
            /* 先两端再平分剩余空间 */
            justify-content: space-between;
            
        }
        #os{
            width: 100px;
            height: 100px;
            background-color: rebeccapurple;
        }
    </style>
</head>
<body>
    <div id="obox">
        <div id="os">1</div>
        <div id="os">2</div>
        <div id="os">3</div>
        <div id="os">4</div>
    </div>
</body>
</html>

flex-wrap

<!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>
        #obox{
            width: 800px;
            height: 600px;
            background-color: aqua ;
            border: 2px solid #222;
            display: flex;
            /* 默认不换行,当子项的宽度比父项宽时,子项会被缩小,这时子项的宽度只是不生效,还是必须要设置的 */
            flex-wrap: nowrap;
            /* 当子项的宽度大于父项的宽度时 换行 */
            /* flex-wrap: wrap; */
        }
        #os{
            width: 400px;
            height: 100px;
            background-color: orange;
            margin: 1px;
        }
    </style>
</head>
<body>
    <h1>flex弹性布局--flex-wrap</h1>
    <div id="obox">
        <div id="os">1</div>
        <div id="os">2</div>
        <div id="os">3</div>
        <div id="os">4</div>
    </div>
</body>
</html>

align-items

<!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>
        .obox{
            width: 100%;
            height: 600px;
            border: 2px solid #222;
            background-color: aqua;
            display: flex;
            /* 默认的是从上到下 */
            align-items: flex-start;
            /* 从下到上 */
            align-items: flex-end;
            /* 居中 */
            align-items: center;
            /* 拉伸:如果项目为设置高度或者高度设置为auto,则拉伸直父项的高度 */
            align-items: stretch;

        }
        .os{
            width: 100px ;
            /* height: 100px; */
            background-color: orange;
            margin: 5px;
        }
    </style>
</head>
<body>
    <h1>flex流式布局--align-items</h1>

    <div class="obox">
        <div class="os">1</div>
        <div class="os">2</div>
        <div class="os">3</div>
        <div class="os">4</div>
    </div>
</body>
</html>

align-content

<!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>
        .obox{
            width: 600px;
            height: 600px;
            border: 2px solid #222;
            background-color: aqua;
            display: flex;
            /* align-content只有当容器内的元素出现了换行或者多行的情况下才会渲染出效果 */
            flex-wrap: wrap;
            align-content: flex-start;
            align-content: flex-end;
            align-content: center;
            align-content: space-around;
            align-content: space-between;
            align-content: stretch;


        }
        .os{
            width: 200px;
            /* height: 200px; */
            background-color: orange;
            margin: 5px;

        }
    </style>
</head>
<body>
    <h1>flex布局--align-content</h1>
    <div class="obox">
        <div class="os">1</div>
        <div class="os">2</div>
        <div class="os">3</div>
        <div class="os">4</div>
    </div>
</body>
</html>


这篇关于Java复习打卡day46的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程