flex布局實例:把色子放進盒子里

目錄

一、flex布局實例:把色子放進盒子里

1、基礎樣式

二、justify-content 屬性

三、flex-direction 屬性

四、align-items 屬性

五、flex-wrap 屬性

二、flex布局應用到常見場景


非常詳細的講解flex布局,看一看,練一練!

一、色子場景示例

核心知識點:display: flex將容器變為彈性容器,內部元素(色子)變為彈性項目,遵循 flex 布局規則。
假設我們有一個盒子(容器)和1- 6 個色子(項目),每個色子代表一個 flex 項目。如果不了解flex布局,請先閱讀? Flex彈性布局


1、基礎樣式

制作色子布局的基礎樣式,以下實例都需要用到如下樣式:

<style>
/* 主容器:使用Flex布局排列6個色子面 */.dice-container {display: flex;flex-wrap: wrap;gap: 20px;padding: 20px;}/* 每個色子面的基本樣式 */.dice {display: flex;width: 100px;height: 100px;border: 2px solid black;border-radius: 10px;background-color: white;padding: 10px;}/* 點的樣式 */.dot {width: 20px;height: 20px;border-radius: 50%;background-color: black;}
</style>
二、justify-content 屬性

?以下是css樣式和html代碼

 .justify-start-example {justify-content: flex-start;}
<div class="dice justify-start-example"><div class="dot"></div>
</div>

以下是css樣式和html代碼

.justify-end-example {justify-content: flex-end;}
    <div class="dice justify-end-example"><div class="dot"></div></div>

以下是css樣式和html代碼

.justify-center-example {justify-content: center;}
<div class="dice justify-center-example"><div class="dot"></div></div>

以下是css樣式和html代碼

.justify-space-between-example {justify-content: space-between;}
<div class="dice justify-space-between-example"><div class="dot"></div><div class="dot"></div></div>

?

?以下是css樣式和html代碼

 .justify-space-around-example {justify-content: space-around;}
<div class="dice justify-space-around-example"><div class="dot"></div><div class="dot"></div></div>

?

?以下是css樣式和html代碼

.justify-space-evenly-example {justify-content: space-evenly;}
<div class="dice justify-space-evenly-example"><div class="dot"></div><div class="dot"></div></div>
三、flex-direction 屬性

以下是css樣式和html代碼

.flex-direction-row {flex-direction: row;}
<div class="dice flex-direction-row"><div class="dot"></div><div class="dot"></div></div>

以下是css樣式和html代碼

.flex-direction-column {flex-direction: column;}
<div class="dice flex-direction-column"><div class="dot"></div><div class="dot"></div></div>

?

以下是css樣式和html代碼

.flex-direction-row-reverse {flex-direction: row-reverse;}
<div class="dice flex-direction-row-reverse"><div class="dot white textcenter">1</div><div class="dot white textcenter">2</div></div>

?

以下是css樣式和html代碼

.flex-direction-column-reverse {flex-direction: column-reverse;}
<div class="dice flex-direction-column-reverse"><div class="dot white textcenter">1</div><div class="dot white textcenter">2</div></div>

?

四、align-items 屬性

以下是css樣式和html代碼

.align-items-flex-start {align-items: flex-start;}
<div class="dice align-items-flex-start"><div class="dot"></div></div>

?

以下是css樣式和html代碼

.align-items-flex-end {align-items: flex-end;}
<div class="dice align-items-flex-end"><div class="dot"></div></div>

?

以下是css樣式和html代碼

.align-items-center {align-items: center;}
<div class="dice align-items-center"><div class="dot"></div></div>

?

以下是css樣式和html代碼

.align-items-baseline {align-items: baseline;}
<div class="dice align-items-baseline"><div style="background-color: aquamarine; padding: 5px; font-size: 12px;">1</div><div style="background-color: aquamarine; padding: 5px; font-size: 28px;">2</div><div style="background-color: aquamarine; padding: 5px; font-size: 18px;">3</div></div>

?

以下是css樣式和html代碼

.align-items-stretch {align-items: stretch;}
<div class="dice align-items-stretch"><div style="background-color: aquamarine; padding: 5px; color:#000">1</div><div style="background-color: aquamarine; padding: 5px; color:#000">2</div></div>

?

五、flex-wrap 屬性

以下是css樣式和html代碼

.flex-wrap-nowrap {flex-wrap: nowrap;}
<div class="dice flex-wrap-nowrap"><div class="dot white textcenter">1</div><div class="dot white textcenter">2</div><div class="dot white textcenter">3</div><div class="dot white textcenter">4</div><div class="dot white textcenter">5</div><div class="dot white textcenter">6</div></div>

以下是css樣式和html代碼

.flex-wrap-wrap {flex-wrap: wrap;}
<div class="dice  flex-wrap-wrap"><div class="dot white textcenter">1</div><div class="dot white textcenter">2</div><div class="dot white textcenter">3</div><div class="dot white textcenter">4</div><div class="dot white textcenter">5</div><div class="dot white textcenter">6</div><div class="dot white textcenter">7</div><div class="dot white textcenter">8</div></div>

?

以下是css樣式和html代碼?

.flex-wrap-wrap-reverse {flex-wrap: wrap-reverse;}
<div class="dice flex-wrap-wrap-reverse"><div class="dot white textcenter">1</div><div class="dot white textcenter">2</div><div class="dot white textcenter">3</div><div class="dot white textcenter">4</div><div class="dot white textcenter">5</div><div class="dot white textcenter">6</div><div class="dot white textcenter">7</div><div class="dot white textcenter">8</div></div>

?

二、flex布局應用到常見場景

.dice.one {justify-content: center;align-items: center;}

 /* 兩點:對角 */.dice.two {justify-content: space-between;}.dice.two .dot:nth-child(2) {align-self: flex-end;}

?

/* 三點:對角 */.dice.three {justify-content: space-between;}.dice.three .dot:nth-child(2) {align-self: center;}.dice.three .dot:nth-child(3) {align-self: flex-end;}

?

/* 四點:2x2網格 */.dice.four {flex-wrap: wrap;justify-content: space-between;align-content: space-between;}.dice.four .column {flex-basis: 100%;display: flex;justify-content: space-between;}

?

/* 五點:4角+中心 */.dice.five {flex-wrap: wrap;justify-content: space-between;align-content: space-between;}.dice.five .column {flex-basis: 100%;display: flex;justify-content: space-between;}.dice.five .column:nth-child(2) {justify-content: center;}

?

/* 六點:3x2網格 */.dice.six {flex-wrap: wrap;justify-content: space-between;align-content: space-between;}.dice.six .column {flex-basis: 100%;display: flex;justify-content: space-between;}

實例結合理論【 flex布局基礎知識 】一定能做的很好!小伙伴們動手練習起來吧!

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/89073.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/89073.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/89073.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Netty編解碼器

目錄 1、概念 2、Netty提供的編解碼器類型 2.1 解碼器 2.1.1 ByteToMessageDecoder 2.1.2 ReplayingDecoder 2.1.3 MessageToMessageDecoder 2.2 編碼器 2.2.1 MessageToByteEncoder 2.2.2 MessageToMessageEncoder 2.3 編解碼器 2.3.1 ByteToMessageCodec 2.3.2 M…

企業內部安全組網技術解析:安全通道選型、零信任架構與數據合規加密防護

一、引言&#xff1a;企業內部安全組網的重要性 隨著企業數字化轉型的深入以及遠程辦公需求的增加&#xff0c;企業內部異地組網逐漸成為企業信息技術部門關注的重要話題。如何在合規合法的前提下&#xff0c;保障企業內部網絡連接的安全性、穩定性&#xff0c;并有效保護企業…

Windows 4625日志類別解析:未成功的賬戶登錄事件

Windows 4625日志類別解析&#xff1a;未成功的賬戶登錄事件 什么是Windows 4625日志&#xff1f; Windows 4625日志屬于安全日志&#xff08;Security Log&#xff09; 的一部分&#xff0c;記錄系統中未成功的賬戶登錄嘗試&#xff08;Failed Logon&#xff09;。它是追蹤非…

3D看房實現房屋的切換

作為3D看房的補充&#xff0c;在這里&#xff0c;我們講一下如何實現房屋的切換&#xff0c;我這里提供兩種思路&#xff0c; 切換貼圖&#xff0c;切換場景&#xff0c; 接下我們按照較復雜的場景切換來講&#xff0c;切換貼圖也就水到渠成&#xff1a; 初始化場景&#xf…

[Android]ANR的線程

ANR的原理是進行了超時告警&#xff0c;在執行一個需要被監控的任務時&#xff0c;注冊一個超時提醒&#xff0c;如果很快執行好了&#xff0c;刪除這個提醒&#xff0c;如果超時&#xff0c;這個提醒就被觸發&#xff0c;這個超時處理是通過handler方式來調用的&#xff0c;這…

RLVR來做Agent任務能力增強訓練

和上一篇其實有點承接 上一篇的爭論其實是因為要優化agent的任務規劃和實現能力的 所以有了self-learning之爭 當我們說Self-learning&#xff0c;其實是在說什么&#xff1f; 其實上一篇最后時候提了一點拿RLVR來做agent的任務提升 正好今天看到了一篇應景的論文&#xf…

如何運營一個開源項目并取得較大影響力?

開源不僅是主要的軟件開發方法論&#xff0c;還是助力快速創新、分散協作、 生態系統建設和職業發展的卓越戰略。如今&#xff0c;無論在哪里&#xff0c;都離不開與 開源的互動。開源存在于你的手機、汽車和冰箱中&#xff0c;它使你最喜歡的節 目或電影的制作和發行成為可能&…

華為高斯數據庫的數據類型

華為高斯數據庫的數據類型 國產數據庫華為高斯的GaussDB的數據類型 華為高斯數據庫的數據類型? 一、數值類型&#xff08;Numeric Types&#xff09;? 二、字符類型&#xff08;Character Types&#xff09;? 三、布爾類型&#xff08;Boolean Type&#xff09;? 四、日期和…

生物實驗室安全、化學品安全

zhihu.com/column/c_1922752541369800632 Docs 目錄 第七章 7.1 實驗室生物安全等級 7.1.1 生物安全基本概念 7.1.2 生物的危害等級 7.1.2.1 國內生物危害等級 7.1.3 實驗室生物安全防護水平分級 7.2 實驗室生物安全控制 7.2.1 實驗室生物儀器設備安全控制 7.2.1.1 生…

【QT】第一個QT程序 || 對象樹 || 編碼時的注意事項

一、編寫第一個 Qt 程序 1. 開發環境搭建 安裝 Qt Creator&#xff08;推薦使用官方在線安裝器&#xff09;安裝 Qt 庫&#xff08;如 Qt 5.15.2 或 Qt 6.x&#xff09;配置編譯器&#xff08;MinGW / MSVC / GCC&#xff09; 2. 創建一個簡單的 Qt GUI 應用程序 打開 Qt C…

多服務器IP白名單配置(使用redis stream實現)

應用背景 現在我有一個管理平臺,可以通過代理連接到內網網站,但是這個代理服務器沒有設置密碼,所以需要IP白名單讓指定用戶才可以使用代理。 添加白名單流程圖 流程描述: 登錄管理平臺成功后,管理平臺的后臺將這個登錄的IP地址添加到redis,并設置過期時間為24小時redis…

Vue 3 Teleport 特性

目錄 基本用法? 搭配組件使用? 禁用 Teleport? 多個 Teleport 共享目標? 延遲解析的 Teleport ? 總結 <Teleport> 是一個內置組件&#xff0c;它可以將一個組件內部的一部分模板“傳送”到該組件的 DOM 結構外層的位置去。 基本用法? 有時我們可能會遇到這…

常用指令合集(DOS/Linux/git/Maven等)

文章目錄 常用指令收集vmware 虛擬機聯網設置ubuntu 常見問題設置apt 相關指令&#xff1a;gcc 編譯相關指令 sqlite3VSCode 快捷鍵&#xff1a;收索引擎技巧&#xff08;google&#xff09;Intelideashell--LinxvimgitDOS:mavendockerkubectl 指令nginx配置redis-clientMySQLl…

ABP VNext + MassTransit:構建分布式事務與異步消息協作

ABP VNext MassTransit&#xff1a;構建分布式事務與異步消息協作 &#x1f680; &#x1f4da; 目錄 ABP VNext MassTransit&#xff1a;構建分布式事務與異步消息協作 &#x1f680;&#x1f4da; 1. 背景與動機&#x1f6e0;? 2. 環境與依賴&#x1f527; 3. 在 ABP 模塊…

語義網技術

用通俗語言說語義網技術&#xff0c;以及它和現在互聯網的關系 一、語義網技術&#xff1a;讓網絡“聽懂人話”的智能升級 現有互聯網就像一本巨大的“圖文報紙”&#xff1a;我們人類看文章、圖片能輕松理解意思&#xff0c;但計算機只能識別文字符號&#xff0c;不知道“蘋…

pytorch學習—4.反向傳播(用pytorch算梯度)

2. 線性模型 3.梯度下降算法 4.反向傳播_嗶哩嗶哩_bilibili 4.1 代碼復現 import torch import matplotlib.pyplot as pltx_data=[1.0,2.0,3.0] y_data=[2.0,4.0,6.0]#這里創建了一個PyTorch張量w,初始值為1.0,并且設置requires_grad=True, #這意味著在計算過程中,PyTo…

7類茶葉嫩芽圖像分類數據集

在茶葉育種、溯源管理與自動采摘等智能農業場景中&#xff0c;茶樹品種的識別與分類是一項關鍵任務。不同茶葉品種在嫩芽期表現出顯著的形態差異&#xff0c;例如顏色、葉緣結構、芽頭密度等。因此&#xff0c;基于圖像的茶葉品種分類不僅具備實際應用價值&#xff0c;也為農業…

【Elasticsearch】Linux環境下安裝Elasticsearch

一&#xff0c;前言 Elasticsearch&#xff08;簡稱 ES&#xff09;是一個基于 ??Apache Lucene?? 構建的開源分布式搜索與分析引擎。它支持??實時數據處理??&#xff0c;提供近實時的全文搜索能力&#xff0c;并通過 ??JSON 格式的 RESTful API?? 實現數據索引與檢…

【數據結構--樹于哨兵查找-1】

查找 從前到后- 線性查找 -就是順序查找. 哨兵法查找–節省每次都要判斷是否越界的這一步驟利于節省開銷&#xff0c;從而提升效率。 參考我的程序 #include <stdio.h> #include <stdlib.h> #include <time.h> #include <stdbool.h>#define SIZE …

MyBatis修改(update)操作

1. 三步法口訣 “接口收對象&#xff0c;SQL全賦值&#xff0c;主鍵定目標” 2. 詳細記憶點 | 步驟 | 口訣 | 說明與示例 | |--------------|----------------|----------------------------------------------------------------------------| | 1. 寫接口 | “接口收對象…