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.mzph.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;不…