拿骰子来练习flex布局

简介: 一点css

1053722308.png

一点

css

.root {
    width: 300px;
    height: 300px;
    border-radius: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 1px 2px 8px rgb(0 0 0 / 10%);
}
.p {
    background-color: red;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    box-shadow: 2px 2px 3px rgb(0 0 0 / 20%) inset;
}

html

<div class="root">
    <div class="p"></div>
</div>

二点

css

.root {
    width: 300px;
    height: 300px;
    border-radius: 16px;
    box-shadow: 1px 2px 8px rgb(0 0 0 / 0.1);
    display: flex;
    margin-top:100px;
    justify-content: space-between;
    padding: 12px;
    box-sizing: border-box;
}
.p {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    box-shadow: 2px 2px 3px rgb(0 0 0 / 20%) inset;
    background-color: red;
}
.p:nth-child(2) {
    align-self: flex-end;
}

html

<div class="root">
    <div class="p"></div>
    <div class="p"></div>
</div>

三点

css

.root {
    width: 300px;
    height: 300px;
    border-radius: 16px;
    box-shadow: 1px 2px 8px rgb(0 0 0 / 0.1);
    display: flex;
    margin-top:100px;
    justify-content: space-between;
    padding: 12px;
    box-sizing: border-box;
}
.p {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    box-shadow: 2px 2px 3px rgb(0 0 0 / 20%) inset;
    background-color: red;
}
.p:nth-child(2) {
    align-self: center;
}
.p:nth-child(3) {
    align-self: flex-end;
}

html

<div class="root">
    <div class="p"></div>
    <div class="p"></div>
    <div class="p"></div>
</div>

四点

从4点开始要有分组的思想!且上下排列

css

.root {
    width: 300px;
    height: 300px;
    border-radius: 16px;
    box-shadow: 1px 2px 8px rgb(0 0 0 / 0.1);
    display: flex;
    margin-top:100px;
    padding: 12px;
    box-sizing: border-box;
    flex-direction: column;
    /* justify-content 是设置主轴 */
    /* 主轴 是垂直方向 */
    justify-content: space-between; 
}
.p {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    box-shadow: 2px 2px 3px rgb(0 0 0 / 20%) inset;
    background-color: red;
}
.row {
    display: flex;
    /* justify-content 是设置主轴 */
    /* 主轴 是水平方向 */
    justify-content: space-between;
}

html

<div class="root">
    <div class="row">
        <div class="p"></div>
        <div class="p"></div>
    </div>
    <div class="row">
        <div class="p"></div>
        <div class="p"></div>
    </div>
</div>

五点

css

.root {
    width: 300px;
    height: 300px;
    border-radius: 16px;
    box-shadow: 1px 2px 8px rgb(0 0 0 / 0.1);
    display: flex;
    margin-top: 100px;
    padding: 12px;
    box-sizing: border-box;
    flex-direction: column;
    justify-content: space-between;
}
.p {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    box-shadow: 2px 2px 3px rgb(0 0 0 / 20%) inset;
    background-color: red;
}
.row {
    display: flex;
    justify-content: space-between;
}
.row:nth-child(2) {
    justify-content: center;
}

html

<div class="root">
    <div class="row">
        <div class="p"></div>
        <div class="p"></div>
    </div>
    <div class="row">
        <div class="p"></div>
    </div>
    <div class="row">
        <div class="p"></div>
        <div class="p"></div>
    </div>
</div>

六点

css

.root {
    width: 300px;
    height: 300px;
    border-radius: 16px;
    box-shadow: 1px 2px 8px rgb(0 0 0 / 0.1);
    display: flex;
    margin-top: 100px;
    padding: 12px;
    box-sizing: border-box;
    flex-direction: column;
    justify-content: space-between;
}
.p {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    box-shadow: 2px 2px 3px rgb(0 0 0 / 20%) inset;
    background-color: red;
}
.row {
    display: flex;
    justify-content: space-between;
}

html

<div class="root">
    <div class="row">
        <div class="p"></div>
        <div class="p"></div>
    </div>
    <div class="row">
        <div class="p"></div>
        <div class="p"></div>
    </div>
    <div class="row">
        <div class="p"></div>
        <div class="p"></div>
    </div>
</div>

目录
相关文章
|
5月前
|
开发者 容器
flex 布局属性在实际项目中的应用场景有哪些?
flex 布局属性在实际项目中的应用场景有哪些?
|
4月前
|
前端开发 UED 容器
使用 Flex 布局实现垂直居中效果
【10月更文挑战第7天】
475 57
|
3月前
|
容器
Bootstrap5 Flex(弹性)布局4
排序:.order 类可设置弹性子元素的排序,范围从 .order-1 至 .order-12,数字越小优先级越高。外边距:.ms-auto 和 .me-auto 分别用于设置子元素的右侧和左侧外边距为 auto。包裹:.flex-nowrap(默认)、.flex-wrap 和 .flex-wrap-reverse 用于控制弹性容器中的子元素是否换行及换行方向。
|
2月前
|
容器
Bootstrap5 Flex(弹性)布局6
使用 `.align-self-*` 类可控制指定子元素的对齐方式,包括 `.align-self-start`, `.align-self-end`, `.align-self-center`, `.align-self-baseline`, 和 `.align-self-stretch`。示例代码展示了如何在一个弹性布局中应用这些类,以实现不同设备上的响应式设计。
Bootstrap5 Flex(弹性)布局5
使用 .align-content-* 控制多行子元素在垂直方向上的堆叠方式,如 .align-content-start、.align-content-center 等。对于单行子元素,使用 .align-items-* 控制对齐,例如 .align-items-start、.align-items-center 等。示例代码展示了不同对齐效果的应用。
Bootstrap5 Flex(弹性)布局2
介绍Flex布局的水平和垂直方向控制。`.flex-row`使子元素水平排列,默认左对齐;`.flex-row-reverse`则右对齐。`.flex-column`让子元素垂直排列;`.flex-column-reverse`则反向排列。示例展示了不同类的效果,通过改变类名实现布局调整。
Bootstrap5 Flex(弹性)布局3
`.justify-content-*` 类用于调整弹性子元素的对齐方式,支持 start、end、center、between、around 等值。`.flex-fill` 类使所有子元素等宽,而 `.flex-grow-1` 则让指定子元素占据剩余空间。这些类在布局设计中非常实用。
|
3月前
|
前端开发 UED 容器
在 CSS 中使用 Flex 布局实现页面自适应时需要注意什么?
【10月更文挑战第22天】在使用 Flex 布局实现页面自适应时,需要对其基本原理和特性有深入的理解,同时结合具体的布局需求和场景,进行细致的调整和优化。通过合理的设置和注意事项的把握,才能实现理想的自适应效果,提升用户体验。还可以根据实际情况进行更深入的探索和实践,以不断提升 Flex 布局的应用能力。
|
3月前
|
容器
HTML中使用Flex布局实现双行夹批效果
在HTML中,还可以用table元素来实现双行夹批效果,但比flex布局代码更复杂,效果也不见得更理想。
66 10
|
3月前
|
开发者 UED 容器
鸿蒙next版开发:ArkTS组件通用属性(Flex布局)
在HarmonyOS next中,ArkTS的Flex布局是一种强大且灵活的布局方式,支持水平或垂直方向排列元素,并能动态调整大小和位置以适应不同屏幕。主要属性包括justifyContent、alignItems、direction和wrap,适用于导航栏、侧边栏和表单等多种场景。示例代码展示了如何使用这些属性创建美观的布局。
160 10