弹性盒子学习笔记

1、什么是弹性盒子?

弹性盒子是一种用于按行或列布局元素的一维布局方法。元素可以膨胀以填充额外的空间,收缩以适应更小的空间。

2、弹性项

弹性盒子的子元素称为弹性项。

3、弹性盒子常用属性设置

属性名称属性值描述
displayflex将元素标记为属性盒子
flex-directioncolumn盒子中的元素按列垂直布局
row按行横向排列
row-reverse水平方向反向排列
column-reverse垂直方向反向排列

flex-wrap

nowrap不换行,所有项在一行
wrap换行排列,从上往下排
wrap-reverse换行排列,从下往上排

flex-flow

column wrap

垂直换行排列,是flex-direction

和flex-wrap的简写

justify-content

flex-start

从盒子方向的起始位置

开始排列元素

flex-end从盒子方向的结尾开始排列
center在盒子方向的中心位置排列
space-between

弹性项分布在盒子的方向上,

第一个弹性项在盒子的开始位置,

最后的弹性项在盒子的结束位置

space-around弹性项在盒子方向间隔均匀分布

align-items

stretch | flex-start

| flex-end | center | baseline

弹性项在盒子中的对齐方式
gap10px弹性项之间的距离
row-gap10px行之间的距离
column-gap10px列之间的距离

4、弹性项常用属性设置

属性名称属性值描述

order

1弹性项的顺序,数值越大,越往后排列

flex-grow

1盒子中的元素占多少等份的大小
flex1 80px元素至少80px的大小,然后按相同尺寸分布,flex-grow, flex-shrinkflex-basis的简写

align-self

auto | flex-start | flex-end | center | baseline | stretch;定义元素自身的对齐方式

 案例:

<!DOCTYPE html>
<html lang="en-us">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>Flexbox 0 — starting code</title>
    <style>
        html {
            font-family: sans-serif;
        }

        body {
            margin: 0;
        }

        header {
            background: purple;
            height: 100px;
        }

        h1 {
            text-align: center;
            color: white;
            line-height: 100px;
            margin: 0;
        }

        article {
            padding: 10px;
            margin: 10px;
            background: aqua;
            flex: 200px;
        }

        /* Add your flexbox CSS below here */

        section {
            display: flex;
            /*flex-direction:column;*/
            /*flex-wrap: wrap;*/
            flex-direction:row-reverse;
            flex-flow:row wrap;
        }

        article{
            flex:1 200px;
        }

        article:nth-child(3)
        {
            flex:2 200px;
        }

    </style>
</head>
<body>
    <header>
        <h1>Sample flexbox example</h1>
    </header>

    <section>
        <article>
            <h2>First article</h2>

            <p>Tacos actually microdosing, pour-over semiotics banjo chicharrones retro fanny pack portland everyday carry vinyl typewriter. Tacos PBR&B pork belly, everyday carry ennui pickled sriracha normcore hashtag polaroid single-origin coffee cold-pressed. PBR&B tattooed trust fund twee, leggings salvia iPhone photo booth health goth gastropub hammock.</p>
        </article>

        <article>
            <h2>Second article</h2>

            <p>Tacos actually microdosing, pour-over semiotics banjo chicharrones retro fanny pack portland everyday carry vinyl typewriter. Tacos PBR&B pork belly, everyday carry ennui pickled sriracha normcore hashtag polaroid single-origin coffee cold-pressed. PBR&B tattooed trust fund twee, leggings salvia iPhone photo booth health goth gastropub hammock.</p>
        </article>

        <article>
            <h2>Third article</h2>

            <p>Tacos actually microdosing, pour-over semiotics banjo chicharrones retro fanny pack portland everyday carry vinyl typewriter. Tacos PBR&B pork belly, everyday carry ennui pickled sriracha normcore hashtag polaroid single-origin coffee cold-pressed. PBR&B tattooed trust fund twee, leggings salvia iPhone photo booth health goth gastropub hammock.</p>

            <p>Cray food truck brunch, XOXO +1 keffiyeh pickled chambray waistcoat ennui. Organic small batch paleo 8-bit. Intelligentsia umami wayfarers pickled, asymmetrical kombucha letterpress kitsch leggings cold-pressed squid chartreuse put a bird on it. Listicle pickled man bun cornhole heirloom art party.</p>
        </article>
    </section>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值