批改状态:合格
老师批语:md有序列表语法不对
效果图
<style>* {padding: 0;margin: 0;box-sizing: border-box;}.container {display: flex;flex-flow: column nowrap;}.container .item {width: 5em;height: 5em;border: 1px solid #ccc;padding: 1em;margin: 1em;}</style><body><div class="container"><div class="item">1</div><div class="item">2</div><div class="item">3</div></div></body>







<style>* {padding: 0;margin: 0;box-sizing: border-box;}.container {border: 1px solid #ccc;display: flex;/* 左对齐 */justify-content: flex-start;/* 右对齐 */justify-content: flex-end;/* 居中对齐 */justify-content: center;/* 俩端对齐 */justify-content: space-between;/* 分散对齐 */justify-content: space-around;justify-content: space-evenly;}.container .item {width: 5em;height: 5em;border: 1px solid #ccc;padding: 1em;margin: 1em;}</style><body><div class="container"><div class="item">1</div><div class="item">2</div><div class="item">3</div></div></body>
1、默认拉伸 align-items: stretch;
2、上对齐 align-items: flex-start;
3、下对齐 align-items: flex-end;
4、居中对齐 align-items: center;
1、拉伸 align-content: stretch;
2、上对齐 align-content: flex-start;
3、下对齐 align-content: flex-end;
4、俩端对齐 align-content: space-between;
5、分散对齐 align-content: space-around;
6、平均对齐 align-content: space-evenly;
用在容器项目上的属性 flex:放大因子 收缩因子 基准宽度
默认值 不放大 可收缩 当前容器中的widh;
flex:0 1 auto;
简写flex:initial;
允许放大和收缩
flex:1 1 auto;
简写flex:auto;
禁止放大和收缩
flex:0 0 auto;
简写flex:none;
如果只有一个数字,省掉后面第二个参数表示的是放大因子
flex:1等价于 flex:1 1 auto;
flex通常不会用来设置所有项目的默认选项,通常用来设置某一个项目的特征;
单个项目对齐方式align-self;支持定位项目在主轴上的显示顺序
order:数值
<style>* {padding: 0;margin: 0;box-sizing: border-box;}.container {border: 1px solid #ccc;display: flex;flex-flow: row wrap;}.container .item {width: 5em;height: 5em;border: 1px solid #ccc;padding: 1em;margin: 1em;}.container .item:first-of-type {order: 4;background-color: wheat;}.container .item:last-of-type {order: 1;background-color: yellowgreen;}</style><body><div class="container">'<div class="item">1</div><div class="item">2</div><div class="item">3</div><div class="item">4</div></div></body>
效果图
实际工作中flex嵌套应用很多
<style>* {padding: 0;margin: 0;box-sizing: border-box;}.container {display: flex;}.container .item {width: 5em;height: 5em;border: 1px solid #ccc;padding: 1em;margin: 1em;}.container .item:nth-of-type(4) {display: flex;}</style><body><div class="container"><div class="item">1</div><div class="item">2</div><div class="item">3</div><div class="item">4<div>5</div><div>6</div><div>7</div></div></div></body>
效果图
<style>.box {width: 15em;height: 15em;background-color: seagreen;display: flex;justify-content: center;align-items: center;}.box div {width: 5em;height: 5em;background-color: sienna;}</style><body><div class="box"><div></div></div></body>
效果图
<style>* {margin: 0;padding: 0;box-sizing: border-box;}header,footer {height: 8vh;background-color: steelblue;}.container {height: calc(84vh - 1em);display: flex;margin: .5em 0;}.container aside {min-width: 15em;background-color: turquoise;}.container main {min-width: calc(100% - 31em);background-color: wheat;margin: 0 .5em;}</style><body><header>头部</header><div class="container"><aside>左侧</aside><main>内容</main><aside>右侧</aside></div><footer>底部</footer></body>
效果图
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号