视觉格式化模型Visual formatting model (梁王的理论自习室)(待补充)

前言

未完成

等我看完CSS Mastery的这一章我再回来。

视觉格式化模型在干什么

现在我们声明了许多个盒子和它们的margin,border,padding等等,我们需要确定在屏幕上怎么去组织这些盒子,这就是CSSvisual formatting model的任务

许多个盒子 怎么去组织它们

Visual formatting model

什么是视觉格式化模型

惯例还是上MDN Visual formatting model

The CSS visual formatting model is an algorithm that processes a document and displays it on visual media. This model is a basic concept of CSS.

反正意思就是这个东西是一个算法,把一个document显示到visual media上的算法。(注:visual media指 screens, projectors and paper之类的)

视觉格式化模型把文档里面的每个元素(指的html里面的元素)转化成零个,一个,或多个盒子(boxes)使其符合盒模型(box model)。这些盒子的布局由以下东西决定(详情我在盒子模型的博文里面细讲):

  • 盒子的尺寸: 被精确指明或者限制或者啥也没有说(比如width: 200px; 或 max-width:300px; 或者啥也没说)
  • 盒子的type: inline, inline-level, atomic inline-level, block.
  • 盒子的position: in the normal flow, a float, or absolute positioning.
  • 其他文档树里面的元素,childrens或者neighbors(比如父元素会被子元素撑开)
  • The viewport size and position.(比如width: 100% 还有我不知道overflow那些算不算)
  • Intrinsic dimensions of contained images. (?没理解)
  • Other external information. (没理解)

盒子的生成 (Box generation)

我们知道了盒子和视觉格式化模型有密不可分的关系,盒子的生成式视觉格式化模型的一部分,它从文档中创建了不同类型的盒子,并影响了视觉格式化的完成。盒子的类型主要由display属性决定。

块级元素和块盒子(block boxes)

一个元素如果display属性是 block,list-item 或 table我们就称为块级元素,而块级元素会在垂直方向堆叠。

每个块级元素参与 块级格式化上下文BFC. 每个块级元素生成至少一个块级盒子(block-level box)叫principal block-level box ,一些元素像 list-item 元素, 可能生成更多的盒子来处理bullets(我认为说的应该是前面的小黑点) 和一些其他的印刷元素。更多的还是只生成 principal block-level box.
principal block-level box 包括后代生成的盒子(应该说的是子元素生成的盒子)和生成的内容(generated content). It is also the box involved in the positioning scheme.

一个块级盒子也可以是块容器框(block container box). 块容器框(block container box)是一个盒子,而这个盒子只块容器框只包含块级元素或建立IFC(inline formatting context)行内级元素。这句话其实是块容器框的特性,而不是定义。her block-level boxes, or creates an , thus containing only inline boxes.

It is important to note that the notions of a block-level box and block container box are disjoined. The first, describes how the box behaves with its parents and sibling. The second, how it interacts with its descendants. Some block-level boxes, like tables, aren't block container boxes. Reciprocally, some block container boxes, like non-replaced inline blocks and non-replaced table cells, aren't block-level boxes.

Block-level boxes that also are block container boxes are called block boxes.

image.png

匿名块盒子(Anonymous block boxes)

In some cases, the visual formatting algorithm needs to add supplementary boxes. Because CSS selectors cannot style or name these boxes, they are called anonymous boxes.(比如伪类里面的content还有div里面的内容textnode)

Because selectors do not work with anonymous boxes, they cannot be styled via a stylesheet. This means that all inheritable CSS properties have the inherit value, and all non-inheritable CSS properties, have the initial value.

Block containing boxes contain only inline-level boxes, or only block-level boxes. But often the document contains a mix of both. In that case, anonymous block boxes are created around adjacent inline-level boxes.

EXAMPLE
<div>Some inline text <p>followed by a paragraph</p> followed by more inline text.</div>
image.png

Unlike the <p> element's box, Web developers cannot control the style of the two anonymous boxes. Inheritable properties take the value from the <div>'s property value, like color to define the color of the text, and set the others to the initial value. For example, they won't have a specific background-color, it is always transparent, the initial value for that property, and thus the background of the <div> is visible. A specific background color can be applied to the <p> box. Similarly, the two anonymous boxes always use the same color for their text.

Another case that leads to the creation of anonymous block boxes, is an inline box that contains one or several block boxes. In that case, the box containing the block box is split into two inline boxes: one before, and one after the block box. All the inline boxes before the block box are then enclosed into an anonymous block box, so are the inline boxes following the block box. Therefore, the block box becomes the sibling of the two anonymous block boxes containing the inline elements.

If there are several block boxes, without inline content in-between, the anonymous block boxes are created before, and after the set of boxes.

EXAMPLE

If we take the following HTML code, with <p>have display:inline and <span> have display:block :

<p>Some <em>inline</em> text <span>followed by a paragraph</span> followed by more inline text.</p>

Two anonymous block boxes are created, one for the text before the span Element (Some inline text) and one for the text after it (followed by more inline text), which gives the following block structure:

image.png

行级元素和行级盒子(Inline-level elements and inline boxes)

An element is said to be inline-level when the calculated value of its display CSS property is: inline, inline-block or inline-table. Visually, it doesn't constitute blocks of contents, but is distributed in lines with other inline-level content. Typically, the content of a paragraph with different formatting, like emphasis or images, is made from inline-level elements.
(待补充)

匿名行盒子

(待补充)

正常流、浮动、绝对定位

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,457评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,837评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,696评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,183评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,057评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,105评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,520评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,211评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,482评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,574评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,353评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,213评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,576评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,897评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,174评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,489评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,683评论 2 335

推荐阅读更多精彩内容