扶梯正确使用_乘坐自动扶梯解释CSS浮动
扶梯正确使用
by Kevin Kononenko
凯文·科诺年科(Kevin Kononenko)
乘坐自动扶梯解释CSS浮动 (CSS Floats Explained By Riding An Escalator)
如果您曾经跳过自动扶梯,那么您可以快速了解浮动。 (If you have ever jumped on an escalator, then you can quickly understand floats.)
Your <div> is almost perfect. You decide to introduce some floats to fix the relationship between a few elements.
您的<div>几乎是完美的。 您决定引入一些浮点数来修复一些元素之间的关系。
The next thing you know, your newly floated elements jump out of your carefully chosen order, and stick to the side of your div like a magnet. The phrase “unintended behavior” comes to mind.
接下来您会知道,新浮动的元素会跳出您精心选择的顺序,并像磁铁一样粘在div的一侧。 我想到了“意想不到的行为”。
I’ve personally spent hours trying to fully understand floats. I’d read an article and say, “Oh, this makes sense!” Then I’d return to my code, try it out and… fail. Back to the drawing board.
我个人花费了数小时试图完全理解花车。 我读了一篇文章说:“哦,这很合理!” 然后,我将返回代码,尝试一下,然后…失败。 回到绘图板。
I’m going to do my best to spare you this fate.
我将竭尽全力为您节省命运。
Floats create alternate flows. This is the hardest part to understand. And once you introduce them, you then need to write your code so that it accounts for up to three flows: normal, left and right. This is a whole new set of rules, as opposed to manipulating the width of elements or their positioning.
浮动产生交替的流动 。 这是最难理解的部分。 一旦介绍了它们,就需要编写代码,以便它最多说明三个流程:正常,向左和向右。 这是一组全新的规则,与操纵元素的宽度或其位置相反。
Actually, floats are pretty similar to the dynamics of riding an escalator, and I am going to show how they can be used alongside the clear property to create crystal-clear relationships within divs. This way, the next time you try to use floats in your code, you won’t encounter any surprises.
实际上,花车与乘坐自动扶梯的动力非常相似,我将展示如何将它们与clear属性一起使用,以在div中创建水晶般清晰的关系。 这样,下次您尝试在代码中使用浮点数时,就不会遇到任何意外。
要尊重通过车道 (Gotta respect the pass lane)
The default flow of elements is kind of like the picture above. Some guy is standing in the middle with his hand on the railing. He’s hogging the entire escalator. Nobody can pass him. Pretty poor escalator etiquette, really.
元素的默认流程类似于上图。 有人站在中间,他的手在栏杆上。 他正在占用整个自动扶梯。 没有人可以通过他。 确实,自动扶梯礼节很差。
He is standing behind a bunch of other people that are doing the same thing, so nobody can pass them either. There is no concept of lanes or basic human decency.
他站在一群正在做同样事情的人后面,所以没人能通过他们。 没有车道或基本的人性化的概念。
This is the scenario when you are not using floats at all.
当您根本不使用浮点数时,就是这种情况。
All right, now we’re talking! People showing some level of awareness. Love to see that.
好吧,现在我们在说话! 人们表现出一定程度的意识。 很高兴看到这一点。
We have one lane formed on the left, and another lane formed on the right. Other people can easily move around the two people that are standing still and walk up the escalator more quickly, if they want. Nobody is blocking the flow by standing in the middle.
我们在左侧形成一个车道,在右侧形成另一个车道。 如果他们愿意,其他人可以轻松地在静止不动的两个人周围移动,并更快地走上自动扶梯。 没有人站在中间来阻挡潮流。
This is the scenario when you are using floats in your div. There is a left flow and a right flow, and the elements that are not floated can easily fill the space that is not taken by the floated elements.
在div中使用浮点数时就是这种情况。 有左向流和右向流,未浮动的元素可以轻松填充未浮动元素占用的空间。
浮点数:左右 (Floats: Left and Right)
Using floats can introduce up to two new flows: left and right.
使用浮点数最多可以引入两个新流程:向左和向右。
And this allows the normal flow of elements, those without a float value, to fill in the spaces around these elements.
这样,正常的元素流(没有浮点值的元素)就可以填充这些元素周围的空间。
Floats allow you to create these new relationships between flows.
浮点数使您可以在流之间创建这些新关系。
If you had one line of people standing in the middle of the elevator, you would have limited options for new structures. But when you have a left and right column, suddenly you can specify that certain people stand on the right, other ones stay left, and another group can fill in the gaps.
如果您在电梯中间站着一排人,那么新结构的选择将非常有限。 但是,当您有左右两列时,突然可以指定某些人站在右边,其他人留在左边,而另一组人可以填补空白。
This allows you to create more readable and understandable code, because the float property also gives an indication of an element’s relationship to surrounding elements.
这使您可以创建更具可读性和可理解性的代码,因为float属性还可以指示元素与周围元素的关系。
清除财产 (The Clear Property)
There is one more wrinkle that we have not discussed yet: the clear property. “Clear” allows elements to specify where they should align in comparison to the floated elements.
我们还没有讨论过另外一种皱纹: 透明特性 。 “清除”允许元素指定与浮动元素相比应对齐的位置。
In the first picture of the “Floats” section, the two escalator riders were courteously standing on each side of the escalator. This allows others to pass them and move freely as they wish.
在“浮标”部分的第一张图片中,两个自动扶梯骑手有礼貌地站在自动扶梯的每一侧。 这使其他人可以通过他们并自由移动。
Let’s say that instead of having one floated left element and one floated right element, we instead had 3 floated left elements and 1 on the right. The three floated left elements would stack up in a line on the left if we also give them the “clear: left” property. But if they horizontally aligned with the floated right element, it could make it very difficult or even impossible for the normal flow of elements to pass:
假设我们没有一个浮动的左元素和一个浮动的右元素,而是有3个浮动的左元素和一个右侧的元素。 如果我们还为它们提供了“ clear:left”属性,则三个浮动的left元素将堆积在左侧的一行中。 但是,如果它们与浮动的右元素水平对齐,则可能使元素的正常流通过变得非常困难,甚至不可能:
“Clear: left” tells each person floating left that they should align themselves behind the first element that is floated left. Depending on the size of the bottom two people, it could be challenging for any normal elements to squeeze through and occupy the space on the top right. So even good escalator practices can still lead to blockages.
“清除:左”告诉每个向左浮动的人,他们应该将自己对齐到向左浮动的第一个元素的后面。 根据底部两个人的大小,任何普通元素都可能会挤过并占据右上角的空间。 因此,即使良好的自动扶梯做法也可能导致阻塞。
One of the most frequent uses of the clear property is “clear:both”. This allows you to reset the flow of elements, as opposed to continuing to maintain a right, left and normal flow. It’s kind of like that guy on the escalator who takes up the whole space because he brought his suitcase.
clear属性最常使用的一种是“ clear:both”。 与继续保持向右,向左和正常流动相反,这使您可以重置元素流。 就像自动扶梯上的那个家伙一样,因为他带来了手提箱而占据了整个空间。
With “clear:both”, it doesn’t matter where that one guy is standing in orientation to his suitcase. It doesn’t matter who is standing left or right above him. He’s still blocking the entire escalator. People who get on after him will need to start a new flow of elements, which could include any of the three flows: left, right, or normal.
有了“ clear:both”,无论一个人站在他的手提箱的方位上都没关系。 谁站在他的左上方或右上方都没关系。 他仍然挡住了整个自动扶梯。 追随他的人将需要开始新的元素流程,其中可能包括三个流程中的任何一个:左,右或正常。
He has escaped the three-flow system and reset the rules. Bad for people that want to run up the escalator? Sure. But it’s good if you want to stop anyone from passing.
他逃脱了三流系统并重设了规则。 对想要启动自动扶梯的人不利吗? 当然。 但是,如果您想阻止任何人通过,那就很好了。
Notice how this is different from the one gentleman at the beginning who stood in the middle of the escalator, behind a line of people who were doing the same. That was a one-flow system. “Clear: both” acknowledges that there may be up to three flows, and blocks the passage of any element that follows.
请注意,这与起初坐在自动扶梯中间的那一位绅士有什么不同,那一群人正在做同样的事情。 那是一个单流系统。 “清除:两者”确认最多可能有三个流,并阻止随后的任何元素通过。
If you enjoyed this post, you may also enjoy my other explanations of challenging CSS and JavaScript topics, such as positioning, Model-View-Controller, and callbacks.
如果您喜欢这篇文章,那么您可能还会喜欢我对具有挑战性CSS和JavaScript主题的其他解释 ,例如定位,Model-View-Controller和回调。
And if you think this might help other people in the same position as you, give it a “heart”!
而且,如果您认为这可以帮助与您处于同一位置的其他人,请给它一个“心脏”!
This post originally appeared on the CodeAnalogies blog.
该帖子最初出现在CodeAnalogies博客上 。
翻译自: https://www.freecodecamp.org/news/css-floats-explained-by-riding-an-escalator-57fa55232333/
扶梯正确使用
相关文章:

安卓学习-界面-ui-ListView
ListView继承自AbsListView AbsListView属性 XML属性代码说明 android:choiceMode setChoiceMode(int choiceMode) AbsListView.CHOICE_MODE_SINGLEAbsListView.CHOICE_MODE_MULTIPLEAbsListView.CHOICE_MODE_MULTIPLE_MODAL none :无选择模式 singleChoice:允许单…

swift 浮点型字符串的运算
// 1 两个浮点字符串之间的运算 let str1 "1.3"; let str2 "2.4"; let val1 Double(str1); let val2 Double(str2);let val3 CGFloat(Double(str1)!) * CGFloat(Double(str2)!);print(val3);// 2 string 转 double 不失精度 let formattor NumberFo…

为什么要在JavaScript中使用静态类型? (使用Flow进行静态打字的4部分入门)
by Preethi Kasireddy通过Preethi Kasireddy 为什么要在JavaScript中使用静态类型? (使用Flow进行静态打字的4部分入门) (Why use static types in JavaScript? (A 4-part primer on static typing with Flow)) As a JavaScript developer, you can code all day …

客户端如何连接 DataSnap Server 调用服务的方法
一般http访问的地址是 http://localhost:8099/datasnap/rest/TServerMethods1/EchoString/abc 一、用FDConnection1连接Datasnap服务器 FireDAC 连接Datasnap服务端。这个是tcp协议连接通讯,长连接。服务端不是没个方法都建立实例释放实例,而是连接的时…

Solr_全文检索引擎系统
Solr介绍: Solr 是Apache下的一个顶级开源项目,采用Java开发,它是基于Lucene的全文搜索服务。Solr可以独立运行在Jetty、Tomcat等这些Servlet容器中。 Solr的作用: solr是一个现成的全文检索引擎系统, 放入tomcat下可以…

swift 数组 filter reduce sort 等方法
数组的常用方法 swift 数组有很多的操作方法,但是用的时候用常常想不起来,就列出来看看 map 和 flatMap对数组中的元素进行变形操作filter主要对数组进行过滤reduce主要对数组进行计算sort对数组进行排序forEach循环遍历每一个元素min 和 max找出数组中…

im和音视频开发哪个更好_找时间成为更好的开发人员
im和音视频开发哪个更好There’s no time for anything. At least that’s how it feels doesn’t it? No time to learn all the things you think you need to learn to stay ahead of the curve. No time to go back and refactor that ugly piece of code. It works (sort…

4-8 同义词
雅思阅读:剑4~剑8阅读的所有同义词转换 雅思必考词汇 Cambridge 4 TEST 1 1. ignorepay no attentionnot pay any attentiontake no noticenot take any notice忽略,无视v. 2. encounterfaceconfrontmeet遇见,遭遇v. 3. mistaken viewmisconc…

swift可选类型
import UIKitvar array1 ["1","2","3","4","5"];// 1 if let 是一个组合关键字 来进行可选绑定 // 解决Optional对象解包时产生空对象的处理。 for i in array1 {print(i); }if let idx array1.firstIndex(of: "4&q…

java 配置及Eclipse安装
jdk下载 点我~ Java SE Development Kit 8u20 You must accept the Oracle Binary Code License Agreement for Java SE to download this software. Accept License Agreement Decline License Agreement Thank you for accepting the Oracle Binary Code License Agree…

golang 命令行_如何使用Golang编写快速有趣的命令行应用程序
golang 命令行by Peter Benjamin彼得本杰明(Peter Benjamin) 如何使用Golang编写快速有趣的命令行应用程序 (How to write fast, fun command-line applications with Golang) A while back, I wrote an article about “Writing Command-Line Applications in NodeJS”.不久前…

【Pyhon 3】: 170104:优品课堂: GUI -tkinter
from tkinter import * root Tk() root.title("BMS 图书管理系统") lbl Label(root, text书名:)#(1) lbl.pack() #(2) lbl.place(45.50) #(3) web 早期布局,, 常见。 lbl.grid(row0, column0) # web 早期布局,, 常见…

swift Sequence 和 SubSequence
1 序列 Sequence 序列协议是集合类型结构中的基础。 一个序列是代表有一系列具有相同类型的值,并且对这些值进行迭代。 协议中主要有两个参数,一个是元素Element,一个就是迭代器Iterator /// A type representing the sequences elements.…

PDF数据提取------1.介绍
1.关于PDF文件 PDF(Portable Document Format的简称,意为“便携式文件格式”)是由Adobe Systems在1993年用于文件交换所发展出的文件格式。它的优点在于跨平台、能保留文件原有格式(Layout)、开放标准,能自…

javascript_治愈JavaScript疲劳的研究计划
javascriptby Sacha Greif由Sacha Greif 治愈JavaScript疲劳的研究计划 (A Study Plan To Cure JavaScript Fatigue) Like everybody else, I recently came across Jose Aguinaga’s post “How it feels to learn JavaScript in 2016”.像其他所有人一样,我最近遇…

SQL Server中SELECT会真的阻塞SELECT吗?
在SQL Server中,我们知道一个SELECT语句执行过程中只会申请一些意向共享锁(IS) 与共享锁(S), 例如我使用SQL Profile跟踪会话86执行SELECT * FROM dbo.TEST WHERE OBJECT_ID 1 这个查询语句,其申请、释放的锁资源的过程如下所示: 而且从最常见…

appium IOS真机测试
看了 http://blog.csdn.net/today520/article/details/36378805 的文章,终于在真机上面测试成功。 由于没有开发者账号,不能发布应用到机器上面。所以就用了网易新闻的客户端来测试 没有开发者账号,貌似不能真正的开始测试。只能启动一下客户…

siwft 写时复制 Copy-On-Write
写时复制 Copy-On-Write 1 定义 在siwft 标准库中,Array,Dictionary,Set这样的集合类型是通过写时复制来实现的。 import Foundationvar a1 [1,2,3]; var a2 a1;// 将a1 复制给 a2,地址打印结果是相同的// 0x1--0x2--0x3 pri…

超越技术分析_超越技术面试
超越技术分析by Jaime J. Rios由Jaime J. Rios 超越技术面试 (Transcending the Technical Interview) “Wow. What a chastening and shameful experience that was.”“哇。 那真是一种令人st目结舌的经历。” This was my immediate mental reaction after I completed my…

轻松获取LAMP,LNMP环境编译参数配置
轻松获取LAMP,LNMP环境编译参数配置 作者:Mr.Xiong /分类:系统管理 字号:L M S大家是否遇到过去了新公司,公司内的LAMP,LNMP等所有的环境都是配置好的(已经在提供服务了),公司又没有留下部署文档…

java内存分配--引用
栈内存 对象地址 堆内存 存放属性 public class TestDemo{ public static void main(String args[]){ Person perA new Person(); //出现new百分之百就是要申请堆内存 perA.name"王强"; //perA 地址存放在栈内存中,同一块内存只能存…

iOS NSObject对象内存大小
NSObject内存大小 类的本质是结构体 无须赘述 struct NSObject { Class isa; };一个类对象的实例大小是8个字节 之所以打印出的16个字节,是因为一个NSObject 最小开辟16个字节 NSObject *obj [[NSObject alloc]init];// class_getInstanceSize 这是runtime 获…

客户端渲染 服务端渲染_这就是赢得客户端渲染的原因
客户端渲染 服务端渲染A decade ago, nearly everyone was rendering their web applications on the server using technologies like ASP.NET, Ruby on Rails, Java, and PHP.十年前,几乎每个人都使用ASP.NET,Ruby on Rails,Java和PHP等技术…

java多线程三之线程协作与通信实例
多线程的难点主要就是多线程通信协作这一块了,前面笔记二中提到了常见的同步方法,这里主要是进行实例学习了,今天总结了一下3个实例: 1、银行存款与提款多线程实现,使用Lock锁和条件Condition。 附加 :…

Java8中Lambda表达式的10个例子
Java8中Lambda表达式的10个例子 例1 用Lambda表达式实现Runnable接口 Java代码 //Before Java 8: new Thread(new Runnable() { Override public void run() { System.out.println("Before Java8, too much code for too little to do"); } }).start(); …
OC的对象的分类
OC的对象分类 一 oc的对象分类主要分为3种 1 instance 对象: 实例对象就是通过alloc 出来的对象,一个类每一次的alloc都会产生一个新的实例对象 StudentA *a [[StudentA alloc]init];StudentA *b [[StudentA alloc]init];// 打印结果如下 地址是明显…

如何在国内上medium_在Medium上写作的风格指南
如何在国内上mediumAfter spending more than 1,000 hours writing and editing stories for our Medium publication, I’ve decided to create this living style guide for contributors. Feel free to use it for your publication as well.在花了1000多个小时为我们的《中…

C# webform上传图片并生成缩略图
其实里面写的很乱,包括修改文件名什么的都没有仔细去写,主要是想记录下缩略图生成的几种方式 ,大家明白就好! 1 void UpImgs()2 {3 if (FileUpload1.HasFile)4 {5 string fileContentType FileUpload1.Pos…

ios中的自动释放池
自动释放池中是否有虑重功能 1 autoreleasepool { 2 UIView *view [UIView alloc] init] autorelease]; 3 [view autorelease]; 4 } 这样写在自动释放池的队列中是两个对象还是一个对象,就是说把view加到自动释放池的队列时,队列本身是…

arch linux安装_如何从头开始安装Arch Linux
arch linux安装by Andrea Giammarchi由Andrea Giammarchi In this article, youll learn how to install Arch Linux from scratch… and in about 5 minutes. So lets get to it.在本文中,您将学习如何从头开始安装Arch Linux,大约需要5分钟。 因此&am…