css flexbox模型_Flexbox和CSS Grid之間的主要區別

css flexbox模型

by Shaira Williams

由莎拉·威廉姆斯(Shaira Williams)

Flexbox和CSS Grid之間的主要區別 (The main differences between Flexbox and CSS Grid)

Dimensions define the primary demarcation between Flexbox and CSS Grid. Flexbox was designed specifically for one-dimensional layouts, while CSS Grid is engineered to enable two-dimensional layouts. Therefore, CSS Grid can easily render rows and columns simultaneously.

尺寸定義了Flexbox和CSS Grid之間的主要界限。 Flexbox專為一維布局而設計,而CSS Grid被設計為支持二維布局。 因此,CSS Grid可以輕松地同時渲染行和列。

In layperson’s terms, CSS Grid presents a larger canvas, while Flexbox offers minute functionality that operates in a restricted space. The grids have been designed for a two-dimensional organization.

用外行的話來說,CSS Grid會顯示更大的畫布,而Flexbox則提供了在有限空間內運行的微小功能。 網格是為二維組織而設計的。

However, the two specifications share some common points, and if you know how to use flexible boxes, you will find some concepts that will help you to grasp CSS grids.

但是,這兩個規范有一些共同點,如果您知道如何使用靈活框,則會發現一些概念,可以幫助您掌握CSS網格。

In this article, we’ll go through the main differences between Grid and Flexbox, summarized as follows:

在本文中,我們將介紹Grid和Flexbox之間的主要區別,總結如下:

  • Flexbox is designed for one-dimensional layouts, and Grid for two-dimensional layouts.

    Flexbox專為一維布局而設計,而Grid專為二維布局而設計。
  • The approach of CSS Grid is the layout first, while the Flexbox approach is primarily the content.

    CSS Grid的方法首先是布局,而Flexbox的方法則主要是內容。
  • The Flexbox layout is best suited to application components and small-scale layouts, while the Grid layout is designed for larger-scale layouts that are not linear in design.

    Flexbox布局最適合應用程序組件和小規模布局,而Grid布局則設計用于設計中不是線性的大比例布局。

了解Flexbox和網格 (Getting to know Flexbox and Grid)

一維Flexbox (The one-dimensional Flexbox)

CSS Flexible Box Layout (or Flexbox) allows designers to position responsive elements appropriately within screens of different sizes. The tools include:

CSS靈活框布局(或Flexbox)允許設計人員將響應元素適當地放置在不同尺寸的屏幕中。 這些工具包括:

  • box layout for documents,

    文件箱的布局,
  • an inline layout for defining the appearance of text on screens,

    用于定義屏幕上文本外觀的嵌入式布局,
  • a table layout to depict tabular data in one dimension,

    一種表格布局,用于在一維中描述表格數據,
  • and a positioned layout mode that enables explicit positioning of responsive elements.

    以及一種定位的布局模式,可以顯式定位響應元素。

Flexbox is popular among front-end developers, since it allows developers to create multiple instances of dynamic layouts and effortlessly align content within containers.

Flexbox在前端開發人員中很受歡迎,因為它允許開發人員創建動態布局的多個實例,并輕松地在容器內對齊內容。

The flexible box module has been designed as a one-dimensional presentation model and as a method that can provide space distribution between interface elements and powerful alignment functions. When we describe the flexbox as one-dimensional, we describe the fact that flexbox processes layouts in one dimension at a time, as a row or column. This can be compared to the two-dimensional model of the CSS grid layout, which controls columns and rows together.

柔性盒模塊已被設計為一維表示模型,并且被設計為可在界面元素和強大的對齊功能之間提供空間分配的方法。 當我們將flexbox描述為一維時,我們描述的事實是flexbox一次處理一行或一列中的布局。 可以將其與CSS網格布局的二維模型進行比較,后者可以一起控制列和行。

<div class=”wrapper”> <div>One</div> <div>Two</div> <div>Three</div> <div>Four</div> <div>Five</div></div>
.wrapper { width: 500px; display: flex; flex-wrap: wrap;}.wrapper > div { flex: 1 1 150px;}

Pros:

優點:

  • Flex can be arranged in any direction

    柔韌性可以在任何方向上排列
  • Flex can have its visual order reversed or rearranged.

    Flex可以顛倒或重新排列其視覺順序。
  • Items can be aligned in your container or between them.

    項目可以在您的容器中或它們之間對齊。
  • Support all browsers.

    支持所有瀏覽器。

Cons:

缺點:

  • Performance issues

    性能問題

二維網格 (The two-dimensional Grid)

CSS Grid aligns items in columns and rows, allowing developers to easily control the rendering and appearance of large layouts and whole pages meant for the desktop, tablet, and smartphone displays.

CSS Grid使列和行中的項目對齊,從而使開發人員可以輕松控制用于臺式機,平板電腦和智能手機顯示屏的大型布局和整個頁面的呈現和外觀。

Items are placed inside the cells defined by the grid. Creating and defining the overall layouts remains the strong suit for CSS Grid. Internet Explorer, Chrome, Safari, Edge, and Firefox support Grid. Notably, Opera Mini, Blackberry Browser, QQ Browser, and Baidu Browser does not support Grid.

將項目放置在網格定義的單元格內。 創建和定義總體布局仍然是CSS Grid的強項。 Internet Explorer,Chrome,Safari,Edge和Firefox支持Grid。 值得注意的是,Opera Mini,Blackberry Browser,QQ瀏覽器和百度瀏覽器不支持Grid。

It offers automation to create a layout, or define automatic placement rules that perform placements inside a given grid.

它提供了自動創建布局或定義自動放置規則的功能,這些規則可以在給定的網格內執行放置。

<div class=”wrapper”> <div>One</div> <div>Two</div> <div>Three</div> <div>Four</div> <div>Five</div></div>
.wrapper { display: grid; grid-template-columns: repeat(3, 1fr);}

Pros:

優點:

  • Grid tracks are created within your stylesheet.

    網格軌跡是在樣式表中創建的。
  • Reduced file sizes.

    減小文件大小。
  • Prototyping with CSS Grid is fast and efficient.

    使用CSS Grid進行原型制作快速有效。

Cons:

缺點:

  • Not supported by every browser

    并非所有瀏覽器都支持

Flex和Grid之間的差異 (Differences Between Flex and Grid)

尺寸和靈活性 (Dimensionality and Flexibility)

Flexbox offers greater control over alignment and space distribution between items. Being one-dimensional, Flexbox only deals with either columns or rows. This system works for smaller layouts, but cannot render complex displays such as text or document-centric properties that enable floats and columns.

Flexbox可以更好地控制項目之間的對齊方式和空間分配。 由于是一維的,Flexbox只處理列或行。 此系統適用于較小的布局,但無法渲染復雜的顯示,例如啟用浮點數和列的文本或以文檔為中心的屬性。

Grid has two-dimension layout capabilities which allow flexible widths as a unit of length. This compensates for the limitations in Flex.

網格具有二維布局功能,允許靈活的寬度作為長度單位。 這補償了Flex中的限制。

對準 (Alignment)

Flexbox allows fine-tuning of alignments to ensure exact specification sharing. Flex Direction allows developers to align elements vertically or horizontally, which is used when developers create and reverse rows or columns.

Flexbox允許對路線進行微調,以確保確切的規格共享。 Flex Direction允許開發人員垂直或水平對齊元素,這在開發人員創建和反轉行或列時使用。

For broader alignments in both dimensions simultaneously, CSS Grid deploys fractional measure units for grid fluidity and auto-keyword functionality to automatically adjust columns or rows. The in-built automation saves developers from re-work regimes that may potentially originate in confused calculations.

為了同時在兩個維度上進行更廣泛的對齊,CSS Grid部署了分數測量單位以實現網格的流動性和自動關鍵字功能,以自動調整列或行。 內置的自動化功能使開發人員免于可能因混淆計算而產生的返工制度。

項目管理 (Item Management)

Flex Container is the parent element while Flex Item represents the children. The Flex Container can ensure balanced representation by adjusting item dimensions. This allows developers to design for fluctuating screen sizes.

Flex容器是父元素,而Flex項代表子元素。 Flex容器可以通過調整項目尺寸來確保均衡的表示。 這使開發人員可以針對波動的屏幕尺寸進行設計。

For fine-tuning this aesthetic, Grid supports both implicit and explicit content placement. Its inbuilt automation allows it to automatically extend line items and copy values into the new creation from the preceding item.

為了微調這種美感,Grid支持隱式和顯式內容放置。 其內置的自動化功能使其可以自動擴展訂單項,并將值復制到先前項目中的新內容中。

結論 (Conclusion)

Flexbox and CSS Grid both allow a powerful measure of control over their respective domains of front-end development. However, their capabilities are exponentiated when they are combined, utilizing their respective strengths to create an extremely fluid, customizable, beautiful, smooth, and simple experience.

Flexbox和CSS Grid都可以對它們各自的前端開發領域進行有效的控制。 但是,它們的功能在組合時就得到了指數化,利用它們各自的優勢來創造極其流暢,可定制,美觀,流暢和簡單的體驗。

Combining their code also results in a more lightweight setup where abstraction in both domains spills over into the other. There are vast applications to both options, and even more when they are combined into a powerful setup.

組合它們的代碼還可以實現更輕量級的設置,其中兩個域中的抽象都可以溢出到另一個域中。 兩種選擇都有廣泛的應用程序,并且當它們組合成強大的設置時,甚至還會更多。

Learn more about relationship of grid layout to other layout methods here.

在此處了解有關網格布局與其他布局方法的關系的更多信息。

This article has been tipped by members of the techiespad blog.

本文已由techiespad博客成員提供。

翻譯自: https://www.freecodecamp.org/news/the-main-differences-between-flexbox-and-css-grid-667c03461d2b/

css flexbox模型

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

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

相關文章

置信區間估計 預測區間估計_估計,預測和預測

置信區間估計 預測區間估計Estimation implies finding the optimal parameter using historical data whereas prediction uses the data to compute the random value of the unseen data.估計意味著使用歷史數據找到最佳參數&#xff0c;而預測則使用該數據來計算未見數據的…

鴻蒙系統還會推出嗎,華為明年所有自研設備都升級鴻蒙系統,還會推出基于鴻蒙系統的新機...

不負期許&#xff0c;華為鴻蒙OS手機版如期而至。今日(12月15日)&#xff0c;鴻蒙OS 2.0手機開發者Beta版本正式上線&#xff0c;支持運行安卓應用&#xff0c;P40、Mate 30系列可申請公測。國內媒體報道稱&#xff0c;華為消費者業務軟件部副總裁楊海松表示&#xff0c;按照目…

C#中將DLL文件打包到EXE文件

1&#xff1a;在工程目錄增加dll目錄&#xff0c;然后將dll文件復制到此目錄&#xff0c;例如&#xff1a; 2&#xff1a;增加引用&#xff0c;定位到工程的dll目錄&#xff0c;選中要增加的dll文件 3&#xff1a;修改dll文件夾下面的dll文件屬性 選中嵌入式資源&#xff0c;不…

PopupMenu控件的使用

1、用PopupMenu控件能進行右鍵菜單的實現&#xff0c;它的實現還需要綁定到barManager控件上&#xff0c;在barManager的Customize中添加右鍵所需要顯示的功能。 2、PopupMenu屬性欄中綁定Manager為barManager&#xff1b; 3、窗體加載事件中創建 this.popupMenu1.AddItems(new…

Java—動態代理

動態代理利用了JDK API&#xff0c;動態地在內存中構建代理對象&#xff0c;從而實現對目標對象的代理功能。動態代理又被稱為JDK代理或接口代理。 靜態代理與動態代理的區別主要在&#xff1a; 靜態代理在編譯時就已經實現&#xff0c;編譯完成后代理類是一個實際的class文件…

Oracle VM Virtual Box的安裝

安裝Oracle VM Virtual Box安裝擴展插件 選擇"管理"?"全局設定" 在設置對話框中&#xff0c;選擇"擴展" 選擇"添加包" 找到"Oracle_VM_VirtualBox_Extension_Pack-4.1.18-78361"&#xff0c;點擊"打開" 5&#x…

python 移動平均線_Python中的SMA(短期移動平均線)

python 移動平均線With the evolution of technology rapidly evolving, so do strategies in the stock market. In this post, I’ll go over how I created a SMA(Short Moving Average) strategy.隨著技術的飛速發展&#xff0c;股票市場的策略也在不斷發展。 在本文中&…

angular中的href=unsafe:我該怎么擺脫你的溺愛!!

解決方法&#xff1a;angular.module加入下面這行&#xff1a;&#xff08;依據Angular changes urls to “unsafe:” in extension page&#xff09; .config(function($compileProvider){//注:有些版本的angularjs為$compileProvider.urlSanitizationWhitelist(/^\s*(https?…

android view gesturedetector,如何在Android中利用 GestureDetector進行手勢檢測

如何在Android中利用 GestureDetector進行手勢檢測發布時間&#xff1a;2020-11-26 16:15:21來源&#xff1a;億速云閱讀&#xff1a;92作者&#xff1a;Leah今天就跟大家聊聊有關如何在Android中利用 GestureDetector進行手勢檢測&#xff0c;可能很多人都不太了解&#xff0c…

Ubuntu2204配置samba

0.前情說明 samba服務器主要是用來局域網共享文件的&#xff0c;如果想公網共享可能行不通&#xff0c;我已經踩坑一天了 所以說如果你想滿足公網samba共享你就可以不要看下去了 1.參考連接 Ubuntu 安裝 Samba 服務器_ubuntu安裝samba服務器-CSDN博客 2.安裝samba服務 sud…

Java—BIO模型

利用 BIO 模型&#xff08;傳統阻塞 IO 模型&#xff09;實現多用戶訪問 源代碼 Server類 public class server {public static void main(String[] args) {ExecutorService executorService Executors.newFixedThreadPool(6);try {ServerSocket serverSocketnew ServerSocke…

c++學編程如何鍛煉耐力_我如何學習編程:這是一項耐力運動

c學編程如何鍛煉耐力by Amy M Haddad通過艾米M哈達德(Amy M Haddad) 我如何學習編程&#xff1a;這是一項耐力運動 (How I’m learning to program: it’s an endurance sport) 為什么我的編程學習軌跡反映了我作為跑步者的訓練方式 (Why my learning trajectory for programm…

python處理文本數據

處理文本數據&#xff0c;主要是通過Seris的str訪問。遇到NaN時不做任何處理&#xff0c;保留結果為NaN&#xff0c;遇到數字全部處理為NaN。 str是Seris的方法&#xff0c;DataFrame不能直接使用&#xff0c;但是通過索引選擇DataFrame中的某一行或者某一列&#xff0c;結果為…

Java系列筆記(4) - JVM監控與調優【轉】

Java系列筆記(4) - JVM監控與調優【轉】 目錄 參數設置收集器搭配啟動內存分配監控工具和方法調優方法調優實例 光說不練假把式&#xff0c;學習Java GC機制的目的是為了實用&#xff0c;也就是為了在JVM出現問題時分析原因并解決之。通過學習&#xff0c;我覺得JVM監控與調…

Maven打包排除某個資源或者目錄

最近在spark streaming本地調試的時候&#xff0c;引入了一些資源文件&#xff0c;打包的時候需要給排除掉。所以就考慮使用maven的方式 詳細參考官方文檔&#xff1a;https://maven.apache.org/plugins/maven-jar-plugin/examples/include-exclude.html 排除某個資源文件 <…

android發送網絡請求沒反應,Android無法使用HttpURLConnection發送GET請求

我正在嘗試在我的應用程序中使用HttpURLConnection.我將我的請求方法設置為’GET’,但是當我嘗試檢索輸出流時,該方法將更改為’POST’&#xff01;我不確定是什么原因,但是當我使用’POST’發送請求時,我的JSON服務器(我使用JAX-RS)會返回一個空白頁面.這是我的代碼片段&#…

地圖 c-suite_C-Suite的模型

地圖 c-suiteWe’ve all seen a great picture capture an audience of stakeholders.我們所有人都看到了吸引利益相關者聽眾的美好畫面。 Let’s just all notice that the lady in the front right is not captivated by the image on the board (Photo by Christina wocin…

框架和庫的區別_框架和庫之間的區別

框架和庫的區別Developers often use the terms “library” and “framework” interchangeably. But there is a difference.開發人員經常互換使用術語“庫”和“框架”。 但是有區別。 Both frameworks and libraries are code written by someone else that is used to he…

Java—多線程實現生產者消費者模型

采用線程實現“生產者-消費者”編程的基礎模型 源代碼 消費者代碼&#xff1a; public class Consumer implements Runnable {BlockingQueue<Integer> blockingQueue;int n;CountDownLatch countDownLatch;public Consumer(BlockingQueue<Integer> blockingQueue…

動態鏈接庫.so和靜態鏈接庫.a的區別

靜態鏈接庫&#xff1a; ?擴展名&#xff1a;.a? ?編譯行為&#xff1a;在編譯的時候&#xff0c;將函數庫直接整合到執行程序中&#xff08;所以利用靜態庫編譯生成的文檔會更大&#xff09;??獨立執行的狀態&#xff1a;編譯成功的可執行文件可以獨立運行&#xff0c;不…