{"id":644,"date":"2015-11-20T09:51:04","date_gmt":"2015-11-20T17:51:04","guid":{"rendered":"http:\/\/kagan.mactane.org\/blog\/?p=644"},"modified":"2015-11-20T09:53:54","modified_gmt":"2015-11-20T17:53:54","slug":"why-did-my-layout-just-go-all-wonky","status":"publish","type":"post","link":"https:\/\/kagan.mactane.org\/blog\/2015\/11\/20\/why-did-my-layout-just-go-all-wonky\/","title":{"rendered":"Why Did My Layout Just Go All Wonky?"},"content":{"rendered":"<p>If you add Boostrap&#8217;s CSS to a layout that&#8217;s already working just fine, you may find that things shift in strange, subtle ways. And even not-so-subtle ones, like basically your entire layout&nbsp;breaking.<\/p>\n<p>Generally, this seems to manifest as block-level elements becoming too small, and clipping out content inside their bounding boxes. A div that used to be tall enough to hold a a 40-pixel-high navigational icon suddenly cuts off the bottom half of it. The right-floating aside that used to look <em>just right<\/em> now looks oddly too-narrow&nbsp;&mdash; and you don&#8217;t have a screen-shot of its old appearance, but you could <em>swear<\/em> the line-breaks are in different places. Like, maybe, there&#8217;s not quite as much text on each line&nbsp;anymore?<\/p>\n<p>You&#8217;re not going insane. The problem is that you originally built your layout using the W3C box model, where <code>width<\/code> declarations apply <strong>only to the <em>content<\/em> of a box<\/strong> and the <em>padding, border and margin<\/em> are all considered to be &#8220;extra&#8221;, outside that&nbsp;width.<\/p>\n<p>And then you added bootstrap.css, which includes <code class=\"nowrap\">* {box-model: content-box;}<\/code> in&nbsp;it.<\/p>\n<p>And now your layout is using the IE Quirks-mode box model, in which <code>width<\/code> applies to <strong>the visible parts of a box<\/strong>, meaning the <em>padding and border as well as the content<\/em>. This is arguably much more intuitive than the W3C model, but it can also be argued that once you&#8217;re no longer <a href=\"http:\/\/www.greenend.org.uk\/rjk\/misc\/nipple.html\">sucking at your mother&#8217;s nipple<\/a>, &#8220;intuitive&#8221; just means &#8220;whatever you&#8217;ve been trained to&nbsp;expect&#8221;.<\/p>\n<p>So if you weren&#8217;t <em>expecting<\/em> to have all your boxes suddenly be measured from border to border instead of just across the content itself, then you might not consider this &#8220;intuitive&#8221;. But now, hopefully, you&#8217;ll at least <em>recognize<\/em> the problem and know how to fix&nbsp;it.<\/p>\n<div class=\"notice\">Of course, Bootstrap isn&#8217;t the only CSS framework that includes a <code>box-model: content-box<\/code> reset. Now that support for content-box is widespread, <em>lots<\/em> of frameworks and CSS resets are using it. Bootstrap is just the one that happened to <em>actually cause this problem<\/em> in my actual life recently. In case you were thinking this seemed like an unlikely occurrence.<\/div>\n<p>This also serves as a lesson in the importance of <strong>knowing what the heck is inside the third-party libraries and tools you&#8217;re using<\/strong>. Just blindly including without understanding what they do (or how they do it) will lead to problems down the road. (In this case, a scant few feet down the road!) They&#8217;re kind of like abstractions that way&nbsp;&mdash; they have a <a href=\"http:\/\/stackoverflow.com\/questions\/3883006\/meaning-of-leaky-abstraction\">strong tendency to&nbsp;leak<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you add Boostrap&#8217;s CSS to a layout that&#8217;s already working just fine, you may find that things shift in strange, subtle ways. And even not-so-subtle ones, like basically your entire layout&nbsp;breaking. Generally, this seems to manifest as block-level elements becoming too small, and clipping out content inside their bounding boxes. A div that used [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[7,58,69,74],"_links":{"self":[{"href":"https:\/\/kagan.mactane.org\/blog\/wp-json\/wp\/v2\/posts\/644"}],"collection":[{"href":"https:\/\/kagan.mactane.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kagan.mactane.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kagan.mactane.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/kagan.mactane.org\/blog\/wp-json\/wp\/v2\/comments?post=644"}],"version-history":[{"count":2,"href":"https:\/\/kagan.mactane.org\/blog\/wp-json\/wp\/v2\/posts\/644\/revisions"}],"predecessor-version":[{"id":647,"href":"https:\/\/kagan.mactane.org\/blog\/wp-json\/wp\/v2\/posts\/644\/revisions\/647"}],"wp:attachment":[{"href":"https:\/\/kagan.mactane.org\/blog\/wp-json\/wp\/v2\/media?parent=644"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kagan.mactane.org\/blog\/wp-json\/wp\/v2\/categories?post=644"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kagan.mactane.org\/blog\/wp-json\/wp\/v2\/tags?post=644"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}