深度学习所需显存

by Justin Yek

贾斯汀·耶克(Justin Yek)

只需10分钟即可学习基本的Flexbox (Learn basic Flexbox in just 10 minutes)

什么是Flexbox? (What is Flexbox?)

Flexbox, short for “flexible box,” is a layout mode introduced in CSS3 that determines how elements are arranged on a page so that they behave predictably under different screen sizes and devices.

Flexbox是“ flexible box”(柔性框)的缩写,是CSS3中引入的一种布局模式,可确定元素在页面上的排列方式,以便在不同的屏幕尺寸和设备下可预测地运行。

It is called Flexbox because of its ability to expand and shrink elements inside the the flex box to best fill the available space. Compared to older layout methods such as display table and floating inline blocks, Flexbox is a more powerful way to:

之所以称其为Flexbox,是因为它具有在Flex框内扩展和收缩元素以最佳填充可用空间的能力。 与显示表和浮动内联块等较旧的布局方法相比,Flexbox是一种更强大的方法:

  • Lay out elements in different directions沿不同方向布置元素
  • Rearrange the display order of elements重新排列元素的显示顺序
  • Change the alignment of elements更改元素的对齐方式
  • Dynamically fit elements into container动态将元素放入容器中

什么时候不使用Flexbox? (When not to use Flexbox?)

While Flexbox is great for scaling, aligning and re-ordering elements, try to avoid using it for:

尽管Flexbox非常适合缩放,对齐和重新排序元素,但请尽量避免将其用于:

  • overall page layout

    整体页面布局

  • websites which fully support old browsers完全支持旧浏览器的网站

Older browsers, like IE 11 or below, do not support or only partially support Flexbox. If you want to play it safe, you should fall back to other CSS layout methods, such as display: inline-block with float and display: table. However, if you only target modern browsers, Flexbox is definitely worth a look.

较旧的浏览器(例如IE 11或更低版本)不支持Flexbox或仅部分支持Flexbox。 如果您想安全使用它,则应使用其他CSS布局方法,例如display: inline-block with floatdisplay: table 。 但是,如果您仅针对现代浏览器,那么Flexbox绝对值得一看。

术语 (Terminology)

In the Flexbox model, there three core concepts:

在Flexbox模型中,存在三个核心概念:

  • flex items, the elements that need to be laid out弹性项目,需要布置的要素
  • flex container, which contains flex itemsflex容器,其中包含flex项
  • flow direction, which determines the layout direction of flex items流向,确定伸缩项目的布局方向

Humans learn best from experience and examples, so let’s start!

人类可以从经验和示例中学到最好的东西,所以让我们开始吧!

1级-基本 (Level 1 — Basic)

1) Creating a flex container

1)创建一个伸缩容器

<div class="flex-container">    <div class="flex-item"></div>  <div class="flex-item"></div></div>
.flex-container {  display: flex;}

To create a flex container, you just need to add the display: flex property to an element. By default, all direct children are considered flex items and are laid out horizontally in a single row from left to right. If the total width of the flex items is larger than the container, the items will be scaled down so that they will fit into the container.

要创建Flex容器,只需要将display: flex属性添加到元素。 默认情况下,所有直接子级均被视为弹性项目,并从左到右水平排列在一行中。 如果弹性物品的总宽度大于容器的宽度,则物品将按比例缩小,以使其适合容器。

2) Put flex items in a single column

2)将弹性项目放在一栏中

.flex-container {  display: flex;  flex-direction: column;}

Flex items can be laid out vertically by setting flex-direction: column. It is also possible to lay them out in reverse order by setting flex-direction: column-reverse or flex-direction: row-reverse.

可以通过设置flex-direction: column垂直排列Flex项目。 也可以通过设置flex-direction: column-reverseflex-direction: row-reverse以相反的顺序进行布局。

.flex-container {  display: flex;  flex-direction: column-reverse;}

第2级-初学者 (Level 2 — Beginner)

1) Align flex items to the right

1)将弹性项目向右对齐

.flex-container {  display: flex;  justify-content: flex-end;}

Recall that there is flex direction for every Flexbox model. justify-contentis used to specify where the flex items should be placed along the flex direction. In the example above, justify-content: flex-end means items are justified to the end of the flex container in the horizontal direction. That’s why they are placed to the right.

回想一下,每种Flexbox型号都有挠性方向。 justify-content用于指定弹性项目应沿着弹性方向放置的位置。 在上面的示例中, justify-content: flex-end表示项目在水平方向上对齐到flex容器的末端。 因此,它们位于右侧。

2) Center-align flex items

2)中心对齐弹性项目

.flex-container {  display: flex;  justify-content: center;}

3) Spread out flex items

3)摊开弹性物品

You can specify how much space should appear between items in a container by using one of three possible spacing values for thejustify-contentproperty:

您可以使用justify-content属性的三个可能的间距值之一来指定容器中的项目之间应显示多少空间:

  • space-evenly: the space between the starting edge of the container and the first item is equal to the spacing between each item and the item adjacent to it.

    space-evenly :容器的起始边缘与第一个项目之间的距离等于每个项目与其相邻项目之间的距离。

  • space-between: the space between any two adjacent items is the same, but not necessarily equal to the space between the first/last item and its closest edge; the space between the start edge and the first item is equal to the space between the end edge and the last item.

    space-between :两个相邻项目space-between的空间相同,但不一定等于第一个/最后一个项目与其最近边缘之间的空间; 起始边缘和第一项之间的距离等于终止边缘和最后一项之间的距离。

  • space-around: the space on each side of an item is the same for each item in the container. Note that the this means the space between two adjacent items will be twice as large as the space between the first/last item and its closest edge.

    space-around :容器中每个项目的每侧空间都相同。 请注意,这意味着两个相邻项目之间的间隔将是第一个/最后一个项目与其最近边缘之间的间隔的两倍。

4) Align flex items in a second direction

4)在另一个方向上对齐弹性项目

.flex-container {  display: flex;  justify-content: center;  align-items: center;}

Usually, we would like to lay out items along the flex direction while also aligning the items in the direction perpendicular to it. By setting justify-content: center and align-items: center, flex items can be placed at the center of flex container both horizontally and vertically.

通常,我们希望沿弯曲方向布置项目,同时还要在垂直于其方向上对齐项目。 通过设置justify-content: centeralign-items: center ,可以将flex项目水平和垂直放置在flex容器的中心。

5) Align a particular flex item

5)对齐特定的弹性项目

.flex-container {  display: flex;  align-items: center;}
.flex-bottom {  align-self: flex-end;}

It is possible to align a particular flex item differently than the others in the container by using the align-self CSS property on that item.

通过在容器上使用align-self CSS属性,可以使特定的flex项目与容器中的flex项目不同。

3级—中级 (Level 3 — Intermediate)

1) Allow flex items to wrap into other rows/columns

1)允许弹性项目包装到其他行/列中

.flex-container {  display: flex;  flex-wrap: wrap;}

By default, flex items are not allowed to wrap and they are resized to fit into a single row or column if flex container is not large enough for all of them. By adding flex-wrap: wrap, flex items that would overflow the container will be wrapped into another row.

默认情况下,如果flex容器不足以容纳所有柔性物品,则不允许对其进行包装,并且将其调整大小以适合单个行或一列。 通过添加flex-wrap: wrap ,将使容器溢出的flex项目将被包装到另一行中。

2) Reverse wrapping

2)反向包装

.flex-container {  display: flex;  flex-wrap: wrap-reverse;}

Flex items are still laid out in multiple rows flex-wrap: wrap-reverse but they start from the end of flex container.

Flex项仍以多行方式进行flex-wrap: wrap-reverse但它们从flex容器的末尾开始。

3) Justify position of lines of elements

3)证明元素线的位置

.flex-container {  display: flex;  flex-wrap: wrap;  align-content: flex-start;}

By default, rows of flex items that wrapped are stretched to take up all remaining space with equal spacing between adjacent rows. You can set align-content on the flex container to determine the positioning of rows when wrapping occurs. Possible values are flex-start, flex-end, center, space-between, space-around and stretch(default).

默认情况下,包装的弹性项目的行将拉伸以占据所有剩余空间,相邻行之间的距离相等。 您可以在flex容器上设置align-content ,以在发生换行时确定行的位置。 可能的值为flex-startflex-endcenterspace-betweenspace-aroundstretch (默认值)。

4级-高级 (Level 4 — Advanced)

1) Expand elements

1)展开元素

.flex-container {  display: flex;}
.flex-item.nth-of-type(1){  flex-grow: 1;}
.flex-item.nth-of-type(2) {  flex-grow: 2;}

flex-grow takes effect only when there is remaining space in the flex container. The flex-grow property of a flex item specifies how much an item will expand relative to the other items in order to fill the flex box. Default is 1. When set to 0, the item will not grow to fill remaining space at all. In this example, the ratio of two items is 1:2, meaning the first item will take up ⅓, while the second item will take ⅔ of the remaining space.

flex-grow仅在flex容器中有剩余空间时才生效。 弹性项目的flex-grow属性指定一个项目相对于其他项目将膨胀多少,以填充弹性框。 默认值为1。设置为0时,该项目将完全无法填充剩余空间。 在此示例中,两项的比例为1:2,这意味着第一项将占用1/3的空间,而第二项将占用剩余空间的1/3。

2) Shrink elements

2)收缩元素

.flex-container {  display: flex;}
.flex-item:nth-of-type(1) {  flex-shrink: 1;}
.flex-item:nth-of-type(2) {  flex-shrink: 2;}

flex-shrink only takes effect when the flex items overflow the flex container because of insufficient space. It specifies how much an item will shrink relative to the other items in order for the items to not overflow the flex box. Default is 1. When set to 0, the flex item will not shrink at all. In this example, the ratio is 1:2, meaning the first item will shrink by ⅓, while the second item will shrink by ⅔ of the overflowed space.

flex-shrink仅在flex项目由于空间不足而溢出flex容器时才生效。 它指定一个项目相对于其他项目将收缩多少,以使这些项目不会超出柔韧性框。 默认值为1。当设置为0时,flex项将完全不收缩。 在此示例中,该比率为1:2,这意味着第一项将缩小1/3,而第二项将缩小溢出空间的1/3。

3) Set the size of elements

3)设置元素的大小

.flex-container {  display: flex;}
.flex-item.nth-of-type(1) {  flex-basis: 200px;}
.flex-item.nth-of-type(2) {  flex-basis: 10%;}

Instead of using the initial size of an element, you can customize its size with flex-basis. By default, its value is flex-basis: auto, which means the size calculated from non-Flexbox CSS rules. You can also set it to some absolute value or a value that represents a percentage of the flex container; for example flex-basis: 200px and flex-basis: 10%.

您可以使用flex-basis定义元素的大小,而不必使用元素的初始大小。 默认情况下,其值为flex-basis: auto ,这表示从非Flexbox CSS规则计算得出的大小。 您也可以将其设置为某个绝对值或代表flex容器百分比的值; 例如flex-basis: 200pxflex-basis: 10%

4) Put flex-grow, flex-shrink, and flex-basis together

4)将弹性增长,弹性收缩和弹性基础放在一起

.flex-container {  display: flex;}
.flex-item:nth-of-type(1) {  flex: 1 0 100px;}
.flex-item:nth-of-type(2) {  flex: 2 0 10%;}

flex is a shorthand for flex-grow, flex-shrink and flex-basis. In this example, the first flex item is set to be flex-grow=1, flex-shrink=0, flex-basis=100pxand the second flex item is set to be flex-grow=2, flex-shrink=0, flex-basis=10%. In this case , since there is remaining space in the flex container, only flex-grow takes effects and flew-shrink is ignored.

flexflex-growflex-shrinkflex-basis的简写。 在此示例中,第一个弹性项目设置为 flex-grow=1 flex-shrink=0 flex-basis=100px ,第二个flex项目设置为 flex-grow=2 flex-shrink=0 flex-basis=10% 。 在这种情况下,由于flex容器中有剩余空间,因此只有flex-grow起作用并且忽略flew-shrink

结论 (Conclusion)

Flexbox is easy to learn and manipulate. Knowledge of its use is especially helpful since the web development cycle is short and iterations are rapid. If you’d like to experiment more with Flexbox before using it in your projects, you can visit Flexyboxes and Flexbox Froggy to practice. You can also read more on CSS trick: A guide to Flexbox and W3C: CSS Flexible Box.

Flexbox易于学习和操作。 由于Web开发周期短且迭代Swift,因此了解其用法特别有用。 如果要在项目中使用Flexbox之前对其进行更多试验,可以访问Flexyboxes和Flexbox Froggy进行练习。 您还可以阅读有关CSS技巧的更多信息:Flexbox和W3C 指南 :CSS Flexible Box 。

This article was originally published on Altitude Labs’ blog and was written by our software engineer, Felix Yau. Altitude Labs is a software agency that specializes in personalized, mobile-first React apps.

本文最初发布在Altitude Labs的博客上 ,由我们的软件工程师Felix Yau撰写。 Altitude Labs是一家软件代理商,专门研究个性化,移动优先的React应用。

翻译自: https://www.freecodecamp.org/news/flexbox-in-10-minutes-7295497804ed/

深度学习所需显存

深度学习所需显存_只需10分钟即可学习基本的Flexbox相关推荐

  1. 阿里 NIPS 2017 Workshop 论文:基于 TensorFlow 的深度模型训练 GPU 显存优化

    NIPS 2017 在美国长滩举办,场面非常热烈.阿里巴巴一篇介绍深度模型训练 GPU 显存优化的论文<Training Deeper Models by GPU Memory Optimiza ...

  2. LaTex论文作者过多需换行:你只需一步

    LaTex论文作者过多需换行:你只需一步 Wrong Right Wrong \author[1,2]{Mr. Monday}{} \author[1,2]{Mr. Tuesday}{} \autho ...

  3. 自行车车把会吧车刮坏吗_花10分钟即可开始使用车把

    自行车车把会吧车刮坏吗 by Wing Puah 永帕(Wing Puah) 花10分钟即可开始使用车把 (Take 10 minutes to get started with Handlebars ...

  4. 深度学习之GPU显存与利用率 浅析小结

    相信很多人,包括我在内,都对GPU的显存抱有不小的怨念,CUDA out of memory之类的问题一直困扰着咱等,今天这篇文章就是来浅析一下,说不定会有所帮助 首先就一笔带过说一下GPU的重要性吧 ...

  5. 【踩坑】深度学习 Torch 爆显存的原因(显存不够用等问题)

    简介 在深度学习过程中,使用显卡的情况主要有两个过程:一.网络模型训练过程:二.网络模型测试过程.在这两个过程中,都可能存在爆显存或者爆内存的情况.在编程过程中,有很多同学应该都遇到这种情况,本文提供 ...

  6. 深度学习训练降低显存指南

    一.小模块API参数inplace设置为True(省一点点) 比如:Relu()有一个默认参数inplace,默认设置为False,当设置为True时,计算时的得到的新值不会占用新的空间而是直接覆盖原 ...

  7. 关于深度学习中GPU显存使用的介绍

    Reference: 1.https://zhuanlan.zhihu.com/p/31558973 # 知乎上一篇文章介绍显存的使用非常全面 2.https://www.cnblogs.com/kk ...

  8. bert获得词向量_只需几行 Python 代码,即可用 BERT 玩转词嵌入!

    作者 | Anirudh_S 译者 | Sambodhi 编辑 | 张之栋 AI 前线导读: 在自然语言处理领域中,诞生于 2018 年末的 BERT 非常的"火热".强悍如 BE ...

  9. 查看显卡显存_强力散热别浪费 显卡超频这样搞

    点击上方电脑爱好者关注我们 小伙伴们有没有发现,现在的显卡经常是多个版本共用一套散热系统和PCB板,这样看起来有点浪费资源,其实对厂商来说是节约设计成本和时间的.看着那些顶着强力散热器的"低 ...

最新文章

  1. 计算机考试受苦受累,受苦受累真是福作文800字
  2. 用ESX进行虚拟化的技巧连载五:代理/防火墙服务虚拟化
  3. Linux CentOS PhpMyAdmin安装--转载
  4. 关于Element中的clientWidth,scrollWidth,offsetWidth等属性详解
  5. 15、Power Query-行列管理实例应用
  6. 为什么应该用模块取代C/C++中的头文件?
  7. python ==》 元组
  8. php base64_decode 图片,php base64保存为图片,带格式解析
  9. 英特尔发布首款支持 5G NR试验平台 ,离2020年5G商用又进一步
  10. 如何列出所有用户的所有cron作业?
  11. 数值计算原理_JavaScript策略设计时数值计算精度问题解决方案
  12. eCognition易康导出样本
  13. bzoj 4300绝世好题
  14. matlab 平滑曲线拟合散点
  15. 计算机组策略定时开机脚本,简单几步实现电脑定时开机
  16. 加速 SpringBoot 应用开发,官方热部署神器真带劲
  17. CWE 4.7中的新视图:工业控制系统的安全漏洞类别
  18. SM4国密算法实现分析
  19. appium---第一个脚本--启动一个已存在的app
  20. 简单模板,小样,难道简单点不好吗?

热门文章

  1. html百度收录缩略图,百度搜索结果中的缩略图如何替换?
  2. 大学里学到的专业知识到底用到了多少的调查结果
  3. MATLAB绘制 “甲基橙“分子示例图(整活)
  4. mysql insert into on_MySQL之INSERT INTO ON DUPLICATE KEY UPDATE用法详解 | 夕辞
  5. 使用命令行修改注册表中的值
  6. ur10e机械臂与夹爪在gazebo下仿真
  7. wegame搭建饥荒联机服务器教程
  8. 五分钟搞懂游戏开发中的抗锯齿算法
  9. 消息队列超详解(以RabbitMQ和Kafka为例,为何使用消息队列、优缺点、高可用性、问题解决)
  10. spyder突然打不开,只能看到蜘蛛网