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模型

css flexbox模型_Flexbox和CSS Grid之间的主要区别相关推荐

  1. css flexbox模型_Flexbox教程:了解如何使用CSS Flexbox编写响应式导航栏

    css flexbox模型 In this article, I'll explain how to create a navbar which adapts to various screen si ...

  2. css flexbox模型_完整CSS课程-包括flexbox和CSS网格

    css flexbox模型 Learn CSS in this complete 83-part course for beginners. Cascading Style Sheets (CSS) ...

  3. css flexbox模型_Flexbox-Ultimate CSS Flex速查表(带有动画图!)

    css flexbox模型 This comprehensive CSS flexbox cheatsheet will cover everything you need to know to st ...

  4. css flexbox模型_如何将Flexbox后备添加到CSS网格

    css flexbox模型 I shared how to build a calendar with CSS Grid in the previous article. Today, I want ...

  5. css flexbox模型_5分钟内学习CSS Flexbox-初学者教程

    css flexbox模型 快速介绍流行的布局模块 (A quick introduction to the popular layout module) In this post, you'll l ...

  6. css flexbox模型_代码简介:CSS Flexbox有点像旅行

    css flexbox模型 Here are three stories we published this week that are worth your time: 这是我们本周发布的三个值得您 ...

  7. css flexbox模型_CSS Flexbox在全国范围内的公路旅行中得到了解释

    css flexbox模型 by Kevin Kononenko 凯文·科诺年科(Kevin Kononenko) CSS Flexbox在全国范围内的公路旅行中得到了解释 (CSS Flexbox ...

  8. css flexbox模型_通过Flexbox Froggy游戏自学CSS Flexbox

    过去,我们只介绍了flexbox及其工作原理. 但是实际上将flexbox应用于您的工作流程可能会遇到挑战,因为它是CSS规范中如此复杂的补充. 使用Flexbox Froggy,您可以通过有趣的涉及 ...

  9. css盒子模型_说说css盒子模型

    什么是盒模型 引用MDN官方的解释: 当对一个文档进行布局(lay out)的时候,浏览器的渲染引擎会根据标准之一的 CSS 基础框盒模型(CSS basic box model),将所有元素表示为一 ...

最新文章

  1. 参加第十六届智能车竞赛同学提问与回答-6-30
  2. 基于消息队列的分布式事务解决方案
  3. webpack超详细配置
  4. [转]EL函数、自定义EL函数、自定义标签
  5. mysql改date格式_mysql数据库修改添加Date格式列的方法
  6. Windbg SOS and CLR版本不一致的解决方案
  7. Potted Flower(线段树+dp)
  8. android手机慢,Android手机运行慢?!教你一秒“提速”50%
  9. 运行 ROS-Academy-for-Beginners
  10. python2和python3同时安装在Windows上
  11. MATLAB实现多元正态Copula分布
  12. 酒店预订管理系统可行性分析
  13. 解决Ubuntu无法定位软件包问题
  14. vue 实现计算器功能
  15. 《人机交互技术》 第七章 Web界面设计
  16. mysql 双引号转义_mysql replace中含有双引号怎么办,试了转义不行
  17. 关于Ubuntu下浏览器不能上网但是能ping通网络的问题
  18. 初识Android 制作一个简单的记账本
  19. 修建道路(最小生成树)
  20. choco 使用详解--window

热门文章

  1. CV2摄像头人脸、人眼、微笑等检测
  2. leetcode1041困于环中的机器人
  3. setdefault()方法
  4. ES6标准入门(第二版)pdf
  5. mysql常用操作(一)
  6. Sass:一种CSS预处理器语言
  7. mysql benchmark基准测试
  8. 第 39 章 ThinkPHP--视图
  9. 为什么内联函数,构造函数,静态成员函数不能为virtual函数
  10. ElasticSearch、Logstash和Kiabana三个开源工具。