{"id":4887,"date":"2020-03-03T23:23:05","date_gmt":"2020-03-03T23:23:05","guid":{"rendered":"http:\/\/b.parsons.edu\/~dejongo\/?p=4887"},"modified":"2022-03-22T18:56:08","modified_gmt":"2022-03-22T18:56:08","slug":"04-how-css-works","status":"publish","type":"post","link":"https:\/\/b.parsons.edu\/~dejongo\/04-how-css-works\/","title":{"rendered":"04 How CSS Works ( w3.org)"},"content":{"rendered":"<p>CSS takes a source document, organized as a <dfn id=\"element-tree\" class=\"dfn-paneled\" data-dfn-for=\"CSS\" data-dfn-type=\"dfn\" data-export=\"\" data-lt=\"element tree\">tree<span id=\"css-element-tree\"><\/span><\/dfn> of <dfn id=\"elements\" class=\"dfn-paneled\" data-dfn-for=\"CSS\" data-dfn-type=\"dfn\" data-export=\"\" data-lt=\"element\">elements<span id=\"css-element\"><\/span><\/dfn> and <dfn id=\"text-nodes\" class=\"dfn-paneled\" data-dfn-for=\"CSS\" data-dfn-type=\"dfn\" data-export=\"\" data-lt=\"text node\">text nodes<span id=\"css-text-node\"><\/span><\/dfn>, and renders it onto a <a href=\"https:\/\/www.w3.org\/TR\/CSS2\/intro.html#canvas\">canvas<\/a>(such as your screen, a piece of paper, or an audio stream). To do this, it generates an intermediary structure, the <dfn id=\"box-tree\" class=\"dfn-paneled\" data-dfn-for=\"CSS\" data-dfn-type=\"dfn\" data-export=\"\">box tree<span id=\"css-box-tree\"><\/span><\/dfn>, which represents the formatting structure of the rendered document. Each <dfn id=\"box\" class=\"dfn-paneled\" data-dfn-for=\"CSS\" data-dfn-type=\"dfn\" data-export=\"\">box<span id=\"css-box\"><\/span><\/dfn> in the <a id=\"ref-for-box-tree\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#box-tree\" data-link-type=\"dfn\">box tree<\/a>represents its corresponding <a id=\"ref-for-elements\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#elements\" data-link-type=\"dfn\">element<\/a> (or <a id=\"ref-for-pseudo-element\" href=\"https:\/\/www.w3.org\/TR\/selectors4\/#pseudo-element\" data-link-type=\"dfn\">pseudo-element<\/a>) in space and\/or time on the canvas, while each <dfn id=\"text-run\" class=\"dfn-paneled\" data-dfn-for=\"CSS\" data-dfn-type=\"dfn\" data-export=\"\">text run<span id=\"css-text-run\"><\/span><\/dfn> in the <span id=\"ref-for-box-tree\u2460\">box tree<\/span> likewise represents the contents of its corresponding <a id=\"ref-for-text-nodes\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#text-nodes\" data-link-type=\"dfn\">text nodes<\/a>.<\/p>\n<p>To create the <a id=\"ref-for-box-tree\u2461\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#box-tree\" data-link-type=\"dfn\">box tree<\/a>, CSS first uses <a href=\"https:\/\/www.w3.org\/TR\/css-cascade\/\">cascading and inheritance<\/a>, to assign a <a id=\"ref-for-computed-value\" href=\"https:\/\/www.w3.org\/TR\/css-cascade-4\/#computed-value\" data-link-type=\"dfn\">computed value<\/a> for each CSS property to each <a id=\"ref-for-elements\u2460\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#elements\" data-link-type=\"dfn\">element<\/a> and <a id=\"ref-for-text-nodes\u2460\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#text-nodes\" data-link-type=\"dfn\">text node<\/a> in the source tree. (See <a href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#biblio-css3-cascade\" data-link-type=\"biblio\">[CSS3-CASCADE]<\/a>.)<\/p>\n<p>Then, for each <a id=\"ref-for-elements\u2461\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#elements\" data-link-type=\"dfn\">element<\/a>, CSS generates zero or more <a id=\"ref-for-box\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#box\" data-link-type=\"dfn\">boxes<\/a> as specified by that element\u2019s <a id=\"ref-for-propdef-display\u2462\" class=\"property\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#propdef-display\" data-link-type=\"propdesc\">display<\/a> property. Typically, an element generates a single <span id=\"ref-for-box\u2460\">box<\/span>, the <a id=\"ref-for-principal-box\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#principal-box\" data-link-type=\"dfn\">principal box<\/a>, which represents itself and contains its contents in the <a id=\"ref-for-box-tree\u2462\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#box-tree\" data-link-type=\"dfn\">box tree<\/a>. However, some <span id=\"ref-for-propdef-display\u2463\" class=\"property\">display<\/span> values (e.g. <span id=\"ref-for-propdef-display\u2464\" class=\"css\">display: list-item<\/span>) generate more than one box (e.g. a <a href=\"https:\/\/www.w3.org\/TR\/CSS2\/visuren.html#principal-box\">principal block box<\/a> and a child <a href=\"https:\/\/www.w3.org\/TR\/CSS2\/generate.html#lists\">marker box<\/a>). And some values (such as <a id=\"ref-for-valdef-display-none\" class=\"css\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#valdef-display-none\" data-link-type=\"maybe\">none<\/a> or <a id=\"ref-for-valdef-display-contents\" class=\"css\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#valdef-display-contents\" data-link-type=\"maybe\">contents<\/a>) cause the <span id=\"ref-for-elements\u2462\">element<\/span>and\/or its descendants to not generate any <span id=\"ref-for-box\u2461\">boxes<\/span> at all. <span id=\"ref-for-box\u2462\">Boxes<\/span> are often referred to by their <span id=\"ref-for-propdef-display\u2465\" class=\"property\">display<\/span> type\u2014<wbr><\/wbr>e.g. a <span id=\"ref-for-box\u2463\">box<\/span> generated by an element with <span id=\"ref-for-propdef-display\u2466\" class=\"css\">display: block<\/span> is called a \u201cblock box\u201d or just a \u201cblock\u201d.<\/p>\n<p>A <a id=\"ref-for-box\u2464\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#box\" data-link-type=\"dfn\">box<\/a> is assigned the same styles as its generating <a id=\"ref-for-elements\u2463\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#elements\" data-link-type=\"dfn\">element<\/a>, unless otherwise indicated. In general, <a id=\"ref-for-inherited-property\" href=\"https:\/\/www.w3.org\/TR\/css-cascade-4\/#inherited-property\" data-link-type=\"dfn\">inherited properties<\/a> are assigned to the <a id=\"ref-for-principal-box\u2460\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#principal-box\" data-link-type=\"dfn\">principal box<\/a>, and then inherit through the box tree to any other boxes generated by the same element. Non-inherited properties default to applying to the <span id=\"ref-for-principal-box\u2461\">principal box<\/span>, but when the element generates multiple boxes, are sometimes defined to apply to a different box: for example, the <a id=\"ref-for-propdef-border\" class=\"property\" href=\"https:\/\/www.w3.org\/TR\/css3-background\/#propdef-border\" data-link-type=\"propdesc\">border<\/a> properties applied to a table element are applied to its <a id=\"ref-for-table-grid-box\" href=\"https:\/\/drafts.csswg.org\/css-tables-3\/#table-grid-box\" data-link-type=\"dfn\">table grid box<\/a>, not to its <span id=\"ref-for-principal-box\u2462\">principal<\/span> <a id=\"ref-for-table-wrapper-box\" href=\"https:\/\/drafts.csswg.org\/css-tables-3\/#table-wrapper-box\" data-link-type=\"dfn\">table wrapper box<\/a>. If the value computation process alters the styles of those boxes, and the element\u2019s style is requested (such as through <code class=\"idl\"><a id=\"ref-for-dom-window-getcomputedstyle\" href=\"https:\/\/www.w3.org\/TR\/cssom-1\/#dom-window-getcomputedstyle\" data-link-type=\"idl\">getComputedStyle()<\/a><\/code>), the element reflects, for each property, the value from the box to which that property was applied.<\/p>\n<p>Similarly, each contiguous sequence of sibling <a id=\"ref-for-text-nodes\u2461\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#text-nodes\" data-link-type=\"dfn\">text nodes<\/a> generates a <a id=\"ref-for-text-run\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#text-run\" data-link-type=\"dfn\">text run<\/a> containing their text contents, which is assigned the same styles as the generating <span id=\"ref-for-text-nodes\u2462\">text nodes<\/span>. If the sequence contains no text, however, it does not generate a <span id=\"ref-for-text-run\u2460\">text run<\/span>.<\/p>\n<p>In constructing the box tree, boxes generated by an element are descendants of the principal box of any ancestor elements. In the general case, the direct <dfn id=\"css-parent-box\" class=\"dfn-paneled\" data-dfn-for=\"CSS\" data-dfn-type=\"dfn\" data-export=\"\">parent box<\/dfn> of an element\u2019s <a id=\"ref-for-principal-box\u2463\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#principal-box\" data-link-type=\"dfn\">principal box<\/a> is the <span id=\"ref-for-principal-box\u2464\">principal box<\/span> of its nearest ancestor element that generates a <a id=\"ref-for-box\u2465\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#box\" data-link-type=\"dfn\">box<\/a>; however, there are some exceptions, such as for <a id=\"ref-for-valdef-display-run-in\" class=\"css\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#valdef-display-run-in\" data-link-type=\"maybe\">run-in<\/a>boxes, display types (like tables) that generate multiple container boxes, and intervening <a id=\"ref-for-anonymous\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#anonymous\" data-link-type=\"dfn\">anonymous boxes<\/a>.<\/p>\n<p>An <dfn id=\"anonymous\" class=\"dfn-paneled\" data-dfn-for=\"CSS\" data-dfn-type=\"dfn\" data-export=\"\" data-lt=\"anonymous|anonymous box\">anonymous box<span id=\"css-anonymous\"><\/span><\/dfn> is a box that is not associated with any element. <a id=\"ref-for-anonymous\u2460\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#anonymous\" data-link-type=\"dfn\">Anonymous boxes<\/a> are generated in certain circumstances to fix up the <a id=\"ref-for-box-tree\u2463\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#box-tree\" data-link-type=\"dfn\">box tree<\/a> when it requires a particular nested structure that is not provided by the boxes generated from the <a id=\"ref-for-element-tree\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#element-tree\" data-link-type=\"dfn\">element tree<\/a>. For example, a <a href=\"https:\/\/www.w3.org\/TR\/CSS2\/tables.html#table-display\">table cell box<\/a> requires a particular type of parent box (the <a href=\"https:\/\/www.w3.org\/TR\/CSS2\/tables.html#table-display\">table row box<\/a>), and will generate an <span id=\"ref-for-anonymous\u2461\">anonymous<\/span> <a href=\"https:\/\/www.w3.org\/TR\/CSS2\/tables.html#table-display\">table row box<\/a> around itself if its parent is not a <a href=\"https:\/\/www.w3.org\/TR\/CSS2\/tables.html#table-display\">table row box<\/a>. (See <a href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#biblio-css2\" data-link-type=\"biblio\">[CSS2]<\/a> \u00a7 <a href=\"https:\/\/www.w3.org\/TR\/CSS2\/tables.html#anonymous-boxes\">17.2.1<\/a>.) Unlike element-generated boxes, whose styles inherit strictly through the element tree, anonymous boxes (which only exist in the <span id=\"ref-for-box-tree\u2464\">box tree<\/span>) <a href=\"https:\/\/www.w3.org\/TR\/css-cascade\/#inheriting\">inherit<\/a> through their <span id=\"ref-for-box-tree\u2465\">box tree<\/span> parentage.<\/p>\n<p>In the course of layout, <a id=\"ref-for-box\u2466\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#box\" data-link-type=\"dfn\">boxes<\/a> and <a id=\"ref-for-text-run\u2461\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#text-run\" data-link-type=\"dfn\">text runs<\/a> can be broken into multiple <a id=\"ref-for-fragment\" href=\"https:\/\/www.w3.org\/TR\/css3-break\/#fragment\" data-link-type=\"dfn\">fragments<\/a>. This happens, for example, when an <a id=\"ref-for-inline-box\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#inline-box\" data-link-type=\"dfn\">inline box<\/a> and\/or <span id=\"ref-for-text-run\u2462\">text run<\/span> is broken across lines, or when a <a id=\"ref-for-block-box\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#block-box\" data-link-type=\"dfn\">block box<\/a> is broken across pages or columns, in a process called <a id=\"ref-for-fragmentation\" href=\"https:\/\/www.w3.org\/TR\/css-break-4\/#fragmentation\" data-link-type=\"dfn\">fragmentation<\/a>. It can also happen due to bidi reordering of text (see <a href=\"https:\/\/www.w3.org\/TR\/css-writing-modes-3\/#bidi-algo\">Applying the Bidirectional Reorderign Algorithm<\/a> in <a href=\"https:\/\/www.w3.org\/TR\/css-writing-modes-3\/#text-direction\">CSS Writing Modes<\/a>) or higher-level <a id=\"ref-for-display-type\" href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#display-type\" data-link-type=\"dfn\">display type<\/a> box splitting, e.g. <a href=\"https:\/\/www.w3.org\/TR\/CSS2\/visuren.html#img-anon-block\">block-in-inline splitting<\/a> (see <a href=\"https:\/\/www.w3.org\/TR\/CSS2\/visuren.html#box-gen\">CSS2\u00a79.2<\/a>) or <a href=\"https:\/\/www.w3.org\/TR\/css-multicol-1\/#spanning-columns\">column-spanner-in-block<\/a> splitting (see <a href=\"https:\/\/www.w3.org\/TR\/css-multicol-1\/#spanning-columns\">CSS Multi-column Layout<\/a>). A <span id=\"ref-for-box\u2467\">box<\/span>therefore consists of one or more <a id=\"ref-for-box-fragment\" href=\"https:\/\/www.w3.org\/TR\/css-break-4\/#box-fragment\" data-link-type=\"dfn\">box fragments<\/a>, and a <span id=\"ref-for-text-run\u2463\">text run<\/span> consists of one or more <span id=\"ref-for-fragment\u2460\">text fragments<\/span>. See <a href=\"https:\/\/www.w3.org\/TR\/2019\/CR-css-display-3-20190711\/#biblio-css3-break\" data-link-type=\"biblio\">[CSS3-BREAK]<\/a> for more information on <span id=\"ref-for-fragmentation\u2460\">fragmentation<\/span>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CSS takes a source document, organized as a tree of elements and text nodes, and renders it onto a canvas(such as your screen, a piece of paper, or an audio stream). To do this, it generates an intermediary structure, the &hellip; <a href=\"https:\/\/b.parsons.edu\/~dejongo\/04-how-css-works\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[11],"tags":[],"_links":{"self":[{"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/posts\/4887"}],"collection":[{"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/comments?post=4887"}],"version-history":[{"count":2,"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/posts\/4887\/revisions"}],"predecessor-version":[{"id":4889,"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/posts\/4887\/revisions\/4889"}],"wp:attachment":[{"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/media?parent=4887"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/categories?post=4887"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/b.parsons.edu\/~dejongo\/wp-json\/wp\/v2\/tags?post=4887"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}