A place to cache linked articles (think custom and personal wayback machine)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.html 50KB

4 yıl önce
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298
  1. <!doctype html><!-- This is a valid HTML5 document. -->
  2. <!-- Screen readers, SEO, extensions and so on. -->
  3. <html lang=fr>
  4. <!-- Has to be within the first 1024 bytes, hence before the <title>
  5. See: https://www.w3.org/TR/2012/CR-html5-20121217/document-metadata.html#charset -->
  6. <meta charset=utf-8>
  7. <!-- Why no `X-UA-Compatible` meta: https://stackoverflow.com/a/6771584 -->
  8. <!-- The viewport meta is quite crowded and we are responsible for that.
  9. See: https://codepen.io/tigt/post/meta-viewport-for-2015 -->
  10. <meta name=viewport content="width=device-width,minimum-scale=1,initial-scale=1,shrink-to-fit=no">
  11. <!-- Required to make a valid HTML5 document. -->
  12. <title>Experiment: Using Flexbox Today (archive) — David Larlet</title>
  13. <!-- Generated from https://realfavicongenerator.net/ such a mess. -->
  14. <link rel="apple-touch-icon" sizes="180x180" href="/static/david/icons/apple-touch-icon.png">
  15. <link rel="icon" type="image/png" sizes="32x32" href="/static/david/icons/favicon-32x32.png">
  16. <link rel="icon" type="image/png" sizes="16x16" href="/static/david/icons/favicon-16x16.png">
  17. <link rel="manifest" href="/manifest.json">
  18. <link rel="mask-icon" href="/static/david/icons/safari-pinned-tab.svg" color="#5bbad5">
  19. <link rel="shortcut icon" href="/static/david/icons/favicon.ico">
  20. <meta name="apple-mobile-web-app-title" content="David Larlet">
  21. <meta name="application-name" content="David Larlet">
  22. <meta name="msapplication-TileColor" content="#da532c">
  23. <meta name="msapplication-config" content="/static/david/icons/browserconfig.xml">
  24. <meta name="theme-color" content="#f0f0ea">
  25. <!-- That good ol' feed, subscribe :p. -->
  26. <link rel=alternate type="application/atom+xml" title=Feed href="/david/log/">
  27. <meta name="robots" content="noindex, nofollow">
  28. <meta content="origin-when-cross-origin" name="referrer">
  29. <!-- Canonical URL for SEO purposes -->
  30. <link rel="canonical" href="http://chriswrightdesign.com/experiments/using-flexbox-today/">
  31. <style>
  32. /* http://meyerweb.com/eric/tools/css/reset/ */
  33. html, body, div, span,
  34. h1, h2, h3, h4, h5, h6, p, blockquote, pre,
  35. a, abbr, address, big, cite, code,
  36. del, dfn, em, img, ins,
  37. small, strike, strong, tt, var,
  38. dl, dt, dd, ol, ul, li,
  39. fieldset, form, label, legend,
  40. table, caption, tbody, tfoot, thead, tr, th, td,
  41. article, aside, canvas, details, embed,
  42. figure, figcaption, footer, header, hgroup,
  43. menu, nav, output, ruby, section, summary,
  44. time, mark, audio, video {
  45. margin: 0;
  46. padding: 0;
  47. border: 0;
  48. font-size: 100%;
  49. font: inherit;
  50. vertical-align: baseline;
  51. }
  52. /* HTML5 display-role reset for older browsers */
  53. article, aside, details, figcaption, figure,
  54. footer, header, hgroup, menu, nav, section { display: block; }
  55. body { line-height: 1; }
  56. blockquote, q { quotes: none; }
  57. blockquote:before, blockquote:after,
  58. q:before, q:after {
  59. content: '';
  60. content: none;
  61. }
  62. table {
  63. border-collapse: collapse;
  64. border-spacing: 0;
  65. }
  66. /* http://practicaltypography.com/equity.html */
  67. /* https://calendar.perfplanet.com/2016/no-font-face-bulletproof-syntax/ */
  68. /* https://www.filamentgroup.com/lab/js-web-fonts.html */
  69. @font-face {
  70. font-family: 'EquityTextB';
  71. src: url('/static/david/css/fonts/Equity-Text-B-Regular-webfont.woff2') format('woff2'),
  72. url('/static/david/css/fonts/Equity-Text-B-Regular-webfont.woff') format('woff');
  73. font-weight: 300;
  74. font-style: normal;
  75. font-display: swap;
  76. }
  77. @font-face {
  78. font-family: 'EquityTextB';
  79. src: url('/static/david/css/fonts/Equity-Text-B-Italic-webfont.woff2') format('woff2'),
  80. url('/static/david/css/fonts/Equity-Text-B-Italic-webfont.woff') format('woff');
  81. font-weight: 300;
  82. font-style: italic;
  83. font-display: swap;
  84. }
  85. @font-face {
  86. font-family: 'EquityTextB';
  87. src: url('/static/david/css/fonts/Equity-Text-B-Bold-webfont.woff2') format('woff2'),
  88. url('/static/david/css/fonts/Equity-Text-B-Bold-webfont.woff') format('woff');
  89. font-weight: 700;
  90. font-style: normal;
  91. font-display: swap;
  92. }
  93. @font-face {
  94. font-family: 'ConcourseT3';
  95. src: url('/static/david/css/fonts/concourse_t3_regular-webfont-20190806.woff2') format('woff2'),
  96. url('/static/david/css/fonts/concourse_t3_regular-webfont-20190806.woff') format('woff');
  97. font-weight: 300;
  98. font-style: normal;
  99. font-display: swap;
  100. }
  101. /* http://practice.typekit.com/lesson/caring-about-opentype-features/ */
  102. body {
  103. /* http://www.cssfontstack.com/ Palatino 99% Win 86% Mac */
  104. font-family: "EquityTextB", Palatino, serif;
  105. background-color: #f0f0ea;
  106. color: #07486c;
  107. font-kerning: normal;
  108. -moz-osx-font-smoothing: grayscale;
  109. -webkit-font-smoothing: subpixel-antialiased;
  110. text-rendering: optimizeLegibility;
  111. font-variant-ligatures: common-ligatures contextual;
  112. font-feature-settings: "kern", "liga", "clig", "calt";
  113. }
  114. pre, code, kbd, samp, var, tt {
  115. font-family: 'TriplicateT4c', monospace;
  116. }
  117. em {
  118. font-style: italic;
  119. color: #323a45;
  120. }
  121. strong {
  122. font-weight: bold;
  123. color: black;
  124. }
  125. nav {
  126. background-color: #323a45;
  127. color: #f0f0ea;
  128. display: flex;
  129. justify-content: space-around;
  130. padding: 1rem .5rem;
  131. }
  132. nav:last-child {
  133. border-bottom: 1vh solid #2d7474;
  134. }
  135. nav a {
  136. color: #f0f0ea;
  137. }
  138. nav abbr {
  139. border-bottom: 1px dotted white;
  140. }
  141. h1 {
  142. border-top: 1vh solid #2d7474;
  143. border-bottom: .2vh dotted #2d7474;
  144. background-color: #e3e1e1;
  145. color: #323a45;
  146. text-align: center;
  147. padding: 5rem 0 4rem 0;
  148. width: 100%;
  149. font-family: 'ConcourseT3';
  150. display: flex;
  151. flex-direction: column;
  152. }
  153. h1.single {
  154. padding-bottom: 10rem;
  155. }
  156. h1 span {
  157. position: absolute;
  158. top: 1vh;
  159. left: 20%;
  160. line-height: 0;
  161. }
  162. h1 span a {
  163. line-height: 1.7;
  164. padding: 1rem 1.2rem .6rem 1.2rem;
  165. border-radius: 0 0 6% 6%;
  166. background: #2d7474;
  167. font-size: 1.3rem;
  168. color: white;
  169. text-decoration: none;
  170. }
  171. h2 {
  172. margin: 4rem 0 1rem;
  173. border-top: .2vh solid #2d7474;
  174. padding-top: 1vh;
  175. }
  176. h3 {
  177. text-align: center;
  178. margin: 3rem 0 .75em;
  179. }
  180. hr {
  181. height: .4rem;
  182. width: .4rem;
  183. border-radius: .4rem;
  184. background: #07486c;
  185. margin: 2.5rem auto;
  186. }
  187. time {
  188. display: bloc;
  189. margin-left: 0 !important;
  190. }
  191. ul, ol {
  192. margin: 2rem;
  193. }
  194. ul {
  195. list-style-type: square;
  196. }
  197. a {
  198. text-decoration-skip-ink: auto;
  199. text-decoration-thickness: 0.05em;
  200. text-underline-offset: 0.09em;
  201. }
  202. article {
  203. max-width: 50rem;
  204. display: flex;
  205. flex-direction: column;
  206. margin: 2rem auto;
  207. }
  208. article.single {
  209. border-top: .2vh dotted #2d7474;
  210. margin: -6rem auto 1rem auto;
  211. background: #f0f0ea;
  212. padding: 2rem;
  213. }
  214. article p:last-child {
  215. margin-bottom: 1rem;
  216. }
  217. p {
  218. padding: 0 .5rem;
  219. margin-left: 3rem;
  220. }
  221. p + p,
  222. figure + p {
  223. margin-top: 2rem;
  224. }
  225. blockquote {
  226. background-color: #e3e1e1;
  227. border-left: .5vw solid #2d7474;
  228. display: flex;
  229. flex-direction: column;
  230. align-items: center;
  231. padding: 1rem;
  232. margin: 1.5rem;
  233. }
  234. blockquote cite {
  235. font-style: italic;
  236. }
  237. blockquote p {
  238. margin-left: 0;
  239. }
  240. figure {
  241. border-top: .2vh solid #2d7474;
  242. background-color: #e3e1e1;
  243. text-align: center;
  244. padding: 1.5rem 0;
  245. margin: 1rem 0 0;
  246. font-size: 1.5rem;
  247. width: 100%;
  248. }
  249. figure img {
  250. max-width: 250px;
  251. max-height: 250px;
  252. border: .5vw solid #323a45;
  253. padding: 1px;
  254. }
  255. figcaption {
  256. padding: 1rem;
  257. line-height: 1.4;
  258. }
  259. aside {
  260. display: flex;
  261. flex-direction: column;
  262. background-color: #e3e1e1;
  263. padding: 1rem 0;
  264. border-bottom: .2vh solid #07486c;
  265. }
  266. aside p {
  267. max-width: 50rem;
  268. margin: 0 auto;
  269. }
  270. /* https://fvsch.com/code/css-locks/ */
  271. p, li, pre, code, kbd, samp, var, tt, time, details, figcaption {
  272. font-size: 1rem;
  273. line-height: calc( 1.5em + 0.2 * 1rem );
  274. }
  275. h1 {
  276. font-size: 1.9rem;
  277. line-height: calc( 1.2em + 0.2 * 1rem );
  278. }
  279. h2 {
  280. font-size: 1.6rem;
  281. line-height: calc( 1.3em + 0.2 * 1rem );
  282. }
  283. h3 {
  284. font-size: 1.35rem;
  285. line-height: calc( 1.4em + 0.2 * 1rem );
  286. }
  287. @media (min-width: 20em) {
  288. /* The (100vw - 20rem) / (50 - 20) part
  289. resolves to 0-1rem, depending on the
  290. viewport width (between 20em and 50em). */
  291. p, li, pre, code, kbd, samp, var, tt, time, details, figcaption {
  292. font-size: calc( 1rem + .6 * (100vw - 20rem) / (50 - 20) );
  293. line-height: calc( 1.5em + 0.2 * (100vw - 50rem) / (20 - 50) );
  294. margin-left: 0;
  295. }
  296. h1 {
  297. font-size: calc( 1.9rem + 1.5 * (100vw - 20rem) / (50 - 20) );
  298. line-height: calc( 1.2em + 0.2 * (100vw - 50rem) / (20 - 50) );
  299. }
  300. h2 {
  301. font-size: calc( 1.5rem + 1.5 * (100vw - 20rem) / (50 - 20) );
  302. line-height: calc( 1.3em + 0.2 * (100vw - 50rem) / (20 - 50) );
  303. }
  304. h3 {
  305. font-size: calc( 1.35rem + 1.5 * (100vw - 20rem) / (50 - 20) );
  306. line-height: calc( 1.4em + 0.2 * (100vw - 50rem) / (20 - 50) );
  307. }
  308. }
  309. @media (min-width: 50em) {
  310. /* The right part of the addition *must* be a
  311. rem value. In this example we *could* change
  312. the whole declaration to font-size:2.5rem,
  313. but if our baseline value was not expressed
  314. in rem we would have to use calc. */
  315. p, li, pre, code, kbd, samp, var, tt, time, details, figcaption {
  316. font-size: calc( 1rem + .6 * 1rem );
  317. line-height: 1.5em;
  318. }
  319. p, li, pre, details {
  320. margin-left: 3rem;
  321. }
  322. h1 {
  323. font-size: calc( 1.9rem + 1.5 * 1rem );
  324. line-height: 1.2em;
  325. }
  326. h2 {
  327. font-size: calc( 1.5rem + 1.5 * 1rem );
  328. line-height: 1.3em;
  329. }
  330. h3 {
  331. font-size: calc( 1.35rem + 1.5 * 1rem );
  332. line-height: 1.4em;
  333. }
  334. figure img {
  335. max-width: 500px;
  336. max-height: 500px;
  337. }
  338. }
  339. figure.unsquared {
  340. margin-bottom: 1.5rem;
  341. }
  342. figure.unsquared img {
  343. height: inherit;
  344. }
  345. @media print {
  346. body { font-size: 100%; }
  347. a:after { content: " (" attr(href) ")"; }
  348. a, a:link, a:visited, a:after {
  349. text-decoration: underline;
  350. text-shadow: none !important;
  351. background-image: none !important;
  352. background: white;
  353. color: black;
  354. }
  355. abbr[title] { border-bottom: 0; }
  356. abbr[title]:after { content: " (" attr(title) ")"; }
  357. img { page-break-inside: avoid; }
  358. @page { margin: 2cm .5cm; }
  359. h1, h2, h3 { page-break-after: avoid; }
  360. p3 { orphans: 3; widows: 3; }
  361. img {
  362. max-width: 250px !important;
  363. max-height: 250px !important;
  364. }
  365. nav, aside { display: none; }
  366. }
  367. ul.with_columns {
  368. column-count: 1;
  369. }
  370. @media (min-width: 20em) {
  371. ul.with_columns {
  372. column-count: 2;
  373. }
  374. }
  375. @media (min-width: 50em) {
  376. ul.with_columns {
  377. column-count: 3;
  378. }
  379. }
  380. ul.with_two_columns {
  381. column-count: 1;
  382. }
  383. @media (min-width: 20em) {
  384. ul.with_two_columns {
  385. column-count: 1;
  386. }
  387. }
  388. @media (min-width: 50em) {
  389. ul.with_two_columns {
  390. column-count: 2;
  391. }
  392. }
  393. .gallery {
  394. display: flex;
  395. flex-wrap: wrap;
  396. justify-content: space-around;
  397. }
  398. .gallery figure img {
  399. margin-left: 1rem;
  400. margin-right: 1rem;
  401. }
  402. .gallery figure figcaption {
  403. font-family: 'ConcourseT3'
  404. }
  405. footer {
  406. font-family: 'ConcourseT3';
  407. display: flex;
  408. flex-direction: column;
  409. border-top: 3px solid white;
  410. padding: 4rem 0;
  411. background-color: #07486c;
  412. color: white;
  413. }
  414. footer > * {
  415. max-width: 50rem;
  416. margin: 0 auto;
  417. }
  418. footer a {
  419. color: #f1c40f;
  420. }
  421. footer .avatar {
  422. width: 200px;
  423. height: 200px;
  424. border-radius: 50%;
  425. float: left;
  426. -webkit-shape-outside: circle();
  427. shape-outside: circle();
  428. margin-right: 2rem;
  429. padding: 2px 5px 5px 2px;
  430. background: white;
  431. border-left: 1px solid #f1c40f;
  432. border-top: 1px solid #f1c40f;
  433. border-right: 5px solid #f1c40f;
  434. border-bottom: 5px solid #f1c40f;
  435. }
  436. </style>
  437. <h1>
  438. <span><a id="jumper" href="#jumpto" title="Un peu perdu ?">?</a></span>
  439. Experiment: Using Flexbox Today (archive)
  440. <time>Pour la pérennité des contenus liés. Non-indexé, retrait sur simple email.</time>
  441. </h1>
  442. <section>
  443. <article>
  444. <h3><a href="http://chriswrightdesign.com/experiments/using-flexbox-today/">Source originale du contenu</a></h3>
  445. <p class="type-dropcap-first">
  446. <span class="type-run-in">Flexbox adds a level of control</span> to our layouts that we didn't really have before, we hacked our floats and clearfixed, we fought whitespace with inline-block, pushed display:table, and even stretched content with position:absolute. We no longer need to rely on these solutions beyond providing something visual to browsers without flex features. Flex's features will add an important set of tools to how we build, not by replacing what was there before, but improving upon how we build today.
  447. </p>
  448. <p>
  449. The major challenge that I see with Flexbox is that there's a distinct gap between what we build today and how we'll approach tomorrow. The prevailing attitude seems to be “Not for another x years”, or “we'll wait for X browser to catch up”, but we don't need to think like this anymore.
  450. </p>
  451. <p>
  452. I don't blame people for finding Flexbox difficult to grasp. Most of the tutorials that exist on the web either show you a bunch of boxes that are completely abstract, or jump so far ahead that the only logical thing to do with Flexbox is to work backward from these magically simple layouts, and end up in a mountain of unmaintainable code. My own previous article was the former, I wrote it to understand Flexbox.
  453. </p>
  454. <p>
  455. These tutorials exist for a purpose, either they're trying to show you what the properties are and what they do, or they're trying to excite you about future possibilities. Both of which I believe they succeed at doing, but there's still a gap - we need a logical, pragmatic approach to start using Flexbox today.
  456. </p>
  457. <h2>Road to Flexbox</h2>
  458. <p>
  459. In this experiment, I'm attempting to show the value of Flexbox
  460. in today's layouts, outline a strategy for adding it and give a few examples of how Flexbox can give current layouts extra powers that we either couldn't achieve, or were difficult to achieve before.
  461. I'll also be documenting some of the common mistakes that I've made while trying to implement it as I believe being able to troubleshoot any new technology's problems is sometimes one of the harder things in picking up something new. My aim is that more people start using Flexbox so that we can push its limits, and get any bugs ironed out, sooner rather than later.
  462. </p>
  463. <p>
  464. If you're not already familiar with Flexbox, this is a follow up of my previous experiment <a href="/experiments/flexbox-adventures/">Flexbox adventures</a>, where I tried to tackle and understand how it actually calculates space and how it might be used in the future. It's full of helpful links that'll bring you up to speed on Flexbox.
  465. </p>
  466. <h2>Making layouts better</h2>
  467. <p>
  468. Flexbox's properties involve a whole array of control over alignment and ordering, and once you get used to how it works, it starts to become clear how little CSS you actually have to write to augment how we're building things today.
  469. </p>
  470. <p>
  471. Do I believe we'll completely drop floats, inline block, or display table? No, and I think educators should still teach students these things even if they do get eventually phased out, it's important to know that sometimes with CSS, we bend, and that's where interesting discoveries are made.
  472. </p>
  473. <p>
  474. Here are some examples of layouts that I believe we can improve quite easily by adding Flexbox.
  475. </p>
  476. <h3>Card Layouts</h3>
  477. <figure class="figure-contained">
  478. <img src="http://chriswrightdesign.com/experiments/img/flex_card-dropbox.png" alt="Dropbox Docu"/>
  479. <figcaption class="caption-below">Card Pattern: Dropbox documentation </figcaption>
  480. </figure>
  481. <p>
  482. The card layout is pretty popular, but in order to get equal height columns you have to set minimum heights, or split lists up into rows. If you don't split them into rows, you have to clear after every row. Flexbox gives us the ability to solve these problems with ease.
  483. </p>
  484. <h3>Split screen layouts</h3>
  485. <figure class="figure-contained">
  486. <img src="http://chriswrightdesign.com/experiments/img/screenshot_atlassian.png" alt="Atlassian"/>
  487. <figcaption class="caption-below">Split Layout pattern: Atlassian </figcaption>
  488. </figure>
  489. <figure class="figure-contained">
  490. <img src="http://chriswrightdesign.com/experiments/img/screenshot_khan.png" alt="Khan Academy"/>
  491. <figcaption class="caption-below">Split Layout pattern: Khan academy </figcaption>
  492. </figure>
  493. <p>
  494. One of the difficulties with split screen is it's reliance on minimum height or position:absolute stretching, making it a pain when moving across screen sizes. Flexbox can just give each item equal height, and then provide you with options for vertical centering with ease.
  495. </p>
  496. <h3>Pinned Layouts</h3>
  497. <figure class="figure-contained">
  498. <img src="http://chriswrightdesign.com/experiments/img/screenshot_danmall.png" alt="Dan Mall's website"/>
  499. <figcaption class="caption-below">Dan Mall uses a pinned layout on the Crayola case study, as recreated in Flexbox by Zoe Gillenwater in <a href="http://zomigi.com/blog/full-width-pinned-layouts-with-flexbox/">this post</a>.</figcaption>
  500. </figure>
  501. <p>
  502. Using the space-between property this layout can be achieved with Flexbox, and give options for ordering and alignment.
  503. </p>
  504. <h3>Newspaper and ad units</h3>
  505. <figure class="figure-contained">
  506. <img src="http://chriswrightdesign.com/experiments/img/screenshot_guardian.png" alt="The Guardian website"/>
  507. <figcaption class="caption-below">Newspaper and ad units, the latest Guardian site uses some Flexbox</figcaption>
  508. </figure>
  509. <p>
  510. The benefit to newspaper layouts and ad units is the ability to order and align. This is just a conceptual idea, and maybe it's stupid in practice - but imagine a system that detects that you don't ever read the sport section - well it can reorder sport toward the bottom of the page and maybe push world news toward the top.
  511. Being able to reorder sections could add simple reader preference reorganization. This is made incredibly simple with Flexbox.
  512. </p>
  513. <h3>Multi-column layouts</h3>
  514. <figure class="figure-contained">
  515. <img src="http://chriswrightdesign.com/experiments/img/screenshot_googlenow.png" alt="Google now"/>
  516. <figcaption class="caption-below">Google now Multi column layout</figcaption>
  517. </figure>
  518. <p>If like me, you thought CSS columns would give you this, and then gave you nothing but broken content blocks - this is one way we can split up a list over multiple columns without having to split up the list in markup.</p>
  519. <h3>Dashboards</h3>
  520. <figure class="figure-contained">
  521. <img src="http://chriswrightdesign.com/experiments/img/screenshot_fitbit.png" alt="Fitbit Dashboard"/>
  522. <figcaption class="caption-below">The Fitbit Dashboard</figcaption>
  523. </figure>
  524. <p>Dashboards offer us another case for ordering, but also could benefit from column wrapping, or equal height columns.</p>
  525. <h2>Embracing change</h2>
  526. <p>
  527. Flexbox aims to solve layout problems that we've hacked to achieve, it allows us to embrace the variable nature of both content and design. It also allows us to accomodate design requests which seem simple to someone who doesn't build, but results in either way too much time, us writing completely unsemantic markup, or way too much code to seem worthwhile. In the future, we'll have more tools like CSS Grid, but for now Flexbox is ready and waiting to be used right now, and we no longer have to bash every layout with the rusty old hammer we've been using for 13+ years.
  528. </p>
  529. <h3>Content is flexible</h3>
  530. <p>
  531. Content is inherently flexible, in the past we’ve designed, built and approached fitting the content to the design rather than fitting the design and build to the content. Even today, we impose restrictions based on build constraints, when we should be relying on the content strategists to impose these restrictions, not the developers.
  532. </p>
  533. <h3>We don't always have control</h3>
  534. <p>
  535. Content management systems are a prime example of where we cede control on layout flexibility - we are often designing with limited knowledge of what content will be within a space. We can achieve things by all kinds of hackery, or we can impose certain rules - but we lose that flexibility when we do.
  536. Some of our approaches to achieving things visually cause us to abandon markup that makes sense and when we stop building in way that makes sense we have to work really hard to make them accessible.
  537. </p>
  538. <h3>More design tools</h3>
  539. <p>
  540. Design often informs what we build and how we build, but so do the tools and constraints of development inform the capabilities of what can be designed. Ideally, a more mature understanding of Flexbox will have us creating better quality, and more varied designs.
  541. </p>
  542. <h3>Bend and break</h3>
  543. <p>
  544. It's not until we fully understand something that we can start to bend it beyond its original purpose to achieve something greater, how we break it influences how we make it.
  545. </p>
  546. <p>
  547. Today, we know the basic rules of Flexbox and what that can do to today's layouts, with education we can influence entirely new layouts, and it won't be until we see Flexbox used in combination with some of the other lesser used, or newer features that we will really start to see the possibilities appear.
  548. </p>
  549. <h2>Strategy for Flexbox</h2>
  550. <p>
  551. To make Flexbox easier to adopt, I decided to look at some of the key criteria in which would make it easy to do so.
  552. </p>
  553. <h3>Build the way we always did</h3>
  554. <p>
  555. We should be able to look at just about any project that we’ve done in the past year and add a piece of code and reap the benefits of Flexbox. We should be able to build a new project tomorrow the way we always did, then add some code that will make Flexbox work and make layouts better.
  556. </p>
  557. <p>
  558. Using a library like Modernizr we can put the new flexbox code behind .flexbox, and optionally put any layout specific to floats (float:left, width:33% etc) behind .no-flexbox so that we can one day phase it out.
  559. </p>
  560. <h3>Minimize code</h3>
  561. <p>
  562. Managing 3 syntaxes plus float layouts just to enable Flexbox is madness. Using an autoprefixer is an integral part of the Flexbox adoption strategy.
  563. </p>
  564. <h3>Make it worthwhile</h3>
  565. <p>
  566. We need our layouts to benefit from Flexbox otherwise we're throwing unnecessary code at a layout for the sake of it. The obvious ones of these involve vertical centering, columns matching their ends, and ordering.
  567. </p>
  568. <h3>Cut the mustard: Flex-wrap</h3>
  569. <p>
  570. Flex-wrap is the point at which Flexbox often becomes useful, it's not necessary for all of these enhancements, but it's the point at which I choose to enhance Flexbox from to prevent layout issues. Fortunately, the Modernizr library's ‘.flexbox’ has flex-wrap as part of its detection, so if you use .flexbox you'll be cutting out browsers which don't support flex-wrap.
  571. </p>
  572. <p>
  573. I've seen talk of people using @supports here, but that cuts out way too many browsers, either write your own feature detection or just use Modernizr.
  574. </p>
  575. <h2>Enhancing with Flexbox</h2>
  576. <p>
  577. To better explain how easy it is to modify existing layouts to flexbox here are two experimental layout enhancements - one with the Card Pattern and one with the Split screen pattern.
  578. </p>
  579. <div class="demo-container t-purple-dark js-demo switch-flexbox">
  580. <div class="demo-control">
  581. <p class="demo-heading">
  582. <h2 class="subheading" id="feature-example">
  583. Example 1: Card layout with list
  584. </h2>
  585. </p>
  586. </div>
  587. <figure class="demo-display l-fullheight">
  588. <ul class="d-flex-card-list js-flex-card-list js-flex-card-justify-flex-start js-flex-card-flexy-no">
  589. <li>
  590. <div class="d-flex-card">
  591. <div class="d-flex-card-image">
  592. <img src="http://chriswrightdesign.com/img/placeholder.jpg"/>
  593. </div>
  594. <div class="d-flex-card-content">
  595. <h3>First</h3>
  596. <p>I'm a card and I'm first.</p>
  597. <a href="#" class="d-flex-card-button">
  598. Button
  599. </a>
  600. </div>
  601. </div>
  602. </li>
  603. <li>
  604. <div class="d-flex-card">
  605. <div class="d-flex-card-image">
  606. <img src="http://chriswrightdesign.com/img/placeholder.jpg"/>
  607. </div>
  608. <div class="d-flex-card-content">
  609. <h3>Second</h3>
  610. <p>I'm a card</p>
  611. <p>I'm some extra content put here to make life more difficult, because I can.</p>
  612. <a href="#" class="d-flex-card-button">
  613. Button
  614. </a>
  615. </div>
  616. </div>
  617. </li>
  618. <li>
  619. <div class="d-flex-card">
  620. <div class="d-flex-card-image">
  621. <img src="http://chriswrightdesign.com/img/placeholder.jpg"/>
  622. </div>
  623. </div>
  624. </li>
  625. <li>
  626. <div class="d-flex-card">
  627. <div class="d-flex-card-image">
  628. <img src="http://chriswrightdesign.com/img/placeholder.jpg"/>
  629. </div>
  630. <div class="d-flex-card-content">
  631. <h3>Fourth</h3>
  632. <p>Dreamcatcher PBR iPhone seitan viral, DIY Truffaut biodiesel slow-carb. Health goth twee migas, messenger bag irony tilde chillwave cold-pressed listicle bespoke Schlitz readymade.</p>
  633. <a href="#" class="d-flex-card-button">
  634. Button
  635. </a>
  636. </div>
  637. </div>
  638. </li>
  639. <li>
  640. <div class="d-flex-card">
  641. <div class="d-flex-card-image">
  642. <img src="http://chriswrightdesign.com/img/placeholder.jpg"/>
  643. </div>
  644. <div class="d-flex-card-content">
  645. <h3>Fifth</h3>
  646. <p>Shabby chic put a bird on it normcore, irony Shoreditch street art hella post-ironic 3 wolf moon fashion axe flexitarian semiotics tote bag. Artisan sriracha aesthetic, Vice Odd Future flannel quinoa disrupt letterpress Banksy selvage.</p>
  647. <a href="#" class="d-flex-card-button">
  648. Button
  649. </a>
  650. </div>
  651. </div>
  652. </li>
  653. </ul>
  654. </figure>
  655. </div>
  656. <h3>How flexbox makes it better</h3>
  657. <p>
  658. We've had a way to layout something like this using floats, but every item is going to appear a different height, so you have to impose a minimum or fixed height to every item to achieve equal height columns, and having the button anchor to the bottom you'd have to make it position absolute, and then pad out the card at the bottom.
  659. </p>
  660. <p>
  661. Once you've done all this, all you have to do is change your screen width to something more narrow where you need the collapse to happen to feel the pain of the monster you've just created. Lots of changing min-heights or your fixed height, and all someone needs to do is add a bit more content than you designed for and you're in a world of hurt.
  662. </p>
  663. <p>
  664. Flexbox solves this, we build the layout how we would have without setting those restrictions (so the columns aren't equal height), add Flexbox and we get all the alignment goodness in just about every modern browser.
  665. </p>
  666. <h3>Step 1: Markup structure</h3>
  667. <p>
  668. I look at this pattern as an unordered list of cards, a card is its own module that lives within a list item.
  669. </p>
  670. <p>
  671. Inside that card are several items of content (image, heading, paragraphs, button). By personal preference of how I might like to stretch the content horizontally on different screens I seperate the content from the image so they can live side by side on float layouts.
  672. </p>
  673. <p>
  674. As I mentioned previously, I'm building how I would've built without Flexbox, it shouldn't really affect my markup structure.
  675. </p>
  676. <pre class="codeblock js-code-is-hidden">
  677. <code class="language-markup">
  678. &lt;!-- card list --&gt;
  679. &lt;ul class="flex-card-list"&gt;
  680. &lt;!-- card list item --&gt;
  681. &lt;li class="flex-card-listitem"&gt;
  682. &lt;!-- card module --&gt;
  683. &lt;div class="flex-card"&gt;
  684. &lt;!-- image container --&gt;
  685. &lt;div class="flex-card-image"&gt;
  686. &lt;img src="http://chriswrightdesign.com/img/placeholder.jpg" /&gt;
  687. &lt;/div&gt;
  688. &lt;!-- content container --&gt;
  689. &lt;div class="flex-card-content"&gt;
  690. &lt;h3 class="flex-card-heading"&gt;First&lt;/h3&gt;
  691. &lt;p&gt;I'm a card and I'm first.&lt;/p&gt;
  692. &lt;a href="#" class="flex-card-button"&gt;Button&lt;/a&gt;
  693. &lt;/div&gt;
  694. &lt;/div&gt;
  695. &lt;/li&gt;
  696. &lt;/ul&gt;
  697. </code>
  698. </pre>
  699. <h3>Step 2: Styling the list</h3>
  700. <p>
  701. On the unordered list we add display:flex, any time we use display:flex we're saying we want to do something with the child elements of that element, in this case our aim is to get the list items to be the same height. Flex will by default stretch items vertically, and lay out on a row. Stretching the list items is the first step to getting the nested items to stretch to the same size.
  702. </p>
  703. <p>
  704. Our list of cards is going to exist on more than one line/row, so we need to use flex-wrap to tell the items to wrap to the next line when they hit the edge of the container.
  705. </p>
  706. <pre class="codeblock js-code-is-hidden">
  707. <code class="language-css">
  708. /* Put behind .flexbox for Feature detection with Modernizr */
  709. .flexbox .flex-card-list {
  710. display:flex;
  711. flex-wrap:wrap;
  712. }
  713. </code>
  714. </pre>
  715. <h3>Step 3: Styling the list items</h3>
  716. <p>
  717. We add display:flex to the list items because we want the card modules to be controllable with flexbox.
  718. </p>
  719. <pre class="codeblock js-code-is-hidden">
  720. <code class="language-css">
  721. .flexbox .flex-card-listitem {
  722. display:flex;
  723. }
  724. </code>
  725. </pre>
  726. <h3>Step 4: Media queries</h3>
  727. <p>
  728. At this point, we add media queries for different screen widths. My layout will go three cards per row, two cards per row, then one card per row.
  729. </p>
  730. <pre class="codeblock js-code-is-hidden">
  731. <code class="language-css">
  732. /* Code to adjust the layout to 2 cards per row */
  733. @media all and (min-width:40em) {
  734. /* Float layout */
  735. .flex-card-list li {
  736. width:50%;
  737. }
  738. .no-flexbox .flex-card-list li {
  739. float:left;
  740. }
  741. }
  742. /* Code to adjust the layout to 3 cards per row */
  743. @media all and (min-width:40em) and (max-width:60em) {
  744. /* Clears the row for 2 item per row layout */
  745. .no-flexbox .flex-card-list li:nth-child(2n+1) {
  746. clear:both;
  747. }
  748. }
  749. @media all and (min-width:60em) {
  750. //common
  751. .flex-card-list li {
  752. width:33.33%;
  753. }
  754. /* Float specific: Clear after every third item */
  755. .no-flexbox .d-flex-card-list li:nth-child(3n+1) {
  756. clear:both;
  757. }
  758. }
  759. </code>
  760. </pre>
  761. <h3>Step 5: The card module</h3>
  762. <p>
  763. We now have a list of objects that change their layout based on media queries, and each item is stretching to the height of the list items. Equal height columns are here, but our buttons are anchored to the paragraph, not to the bottom of the card modules. By adding display flex to the card module we can now use flex to control the image and the content block. We'll also add flex-direction column, since we want to treat it as a full height column.
  764. </p>
  765. <pre class="codeblock js-code-is-hidden">
  766. <code class="language-css">
  767. .flexbox .flex-card {
  768. display:flex;
  769. flex-direction:column;
  770. }
  771. </code>
  772. </pre>
  773. <h3>Step 6: The card content</h3>
  774. <p>
  775. We need to put display:flex on one more item, the card content div, this is so we can control its elements, set its direction to column to let it know we want to use a tube of content and add flex:1 0 auto (thw grow is the important part) to it to let it know to grow to fill the remaining space left behind.
  776. </p>
  777. <pre class="codeblock js-code-is-hidden">
  778. <code class="language-css">
  779. .flexbox .flex-card-content {
  780. display:flex;
  781. flex:1 0 auto; /* We have to add a basis for IE10/11 */
  782. flex-direction:column;
  783. }
  784. </code>
  785. </pre>
  786. <h3>Step 7: Flexible paragraphs</h3>
  787. <p>
  788. It's up to you what you choose to make flexible within the content block, I would use the most variable item, the paragraphs, to grow to fill (add flex:1 0 auto). This will now stretch the bottom of the paragraph and pin the button to the bottom of the card.
  789. </p>
  790. <pre class="codeblock js-code-is-hidden">
  791. <code class="language-css">
  792. .flexbox .flex-card-content p {
  793. flex:1 0 auto; /* We have to add a basis for IE10/11 */
  794. }
  795. </code>
  796. </pre>
  797. <div class="demo-container t-purple-dark js-demo switch-flexbox" id="example2">
  798. <figure class="demo-display l-fullheight l-fullwidth">
  799. <div class="d-flex-split js-flex-split js-flex-align-center js-order-finn">
  800. <div class="d-flex-split-left">
  801. <div class="d-flex-split-image">
  802. <img src="http://chriswrightdesign.com/experiments/img/adventure1.png"/>
  803. </div>
  804. <h3>Finn the human</h3>
  805. <p>Finn (full title: Finn the Human, or Finn Mertens, and formerly known as Pen in the original short), is the main protagonist of the series Adventure Time.
  806. </p>
  807. <a class="d-flex-split-link" href="http://adventuretime.wikia.com/wiki/Finn">Learn more</a>
  808. </div>
  809. <div class="d-flex-split-right js-flex-split-jake">
  810. <div class="d-flex-split-image">
  811. <img src="http://chriswrightdesign.com/experiments/img/adventure2.png"/>
  812. </div>
  813. <h3>Jake the dog</h3>
  814. <p>Jake (full title: Jake the Dog), the deuteragonist of Adventure Time, is a magical dog and Finn's constant companion, best friend, and adoptive brother.</p>
  815. <a class="d-flex-split-link" href="http://adventuretime.wikia.com/wiki/Jake">Learn More</a>
  816. </div>
  817. </div>
  818. </figure>
  819. </div>
  820. <h3>How flexbox makes it better</h3>
  821. <p>
  822. There are a number of approaches one could take to make the split screen layout work - once again we could rely upon a grid row, we could give a minimum height to both items, or we could use the position absolute approach and hook the items to their respective directions (left:0, bottom:0, top:0 etc). Or we could just say be 100vh high, and 50vw wide and ignore how much content there is and throw another div around that content and try to center position that div within its box.
  823. </p>
  824. <p>
  825. The problem to all of these approaches is that we need to dictate a height at some point. Like the previous layout problem - setting minimum heights is problematic across screen sizes (although not such a problem when your layout becomes single column).
  826. </p>
  827. <p>
  828. Adding flexbox solves this and gives us some tools to align all of the content within the container, while allowing the content to dictate the size of the container. You can align it vertically or horizontally any way you like - including the centering it vertically.
  829. </p>
  830. <p>
  831. If we wanted to reorder the children, we can do that too without having to move the items in the DOM.
  832. </p>
  833. <p>
  834. Note: Keyboard control can be an issue when you go down the order path, so i’d say do it sparingly, and probably for larger items that don’t create too much of a jarring experience rather than on smaller items that need lots of tab key presses to get through so your users aren’t jumping all over the screen with the tab key. Consider keyboard users.
  835. </p>
  836. <h3>Step 1: Markup</h3>
  837. <p>
  838. The structure of this experiment is one div (parent), with two divs (children), if there were more than two I'd probably consider this an unordered list - but as there are only two divs will suffice.
  839. </p>
  840. <p>
  841. Inside of each content panel we have an image, a heading, a paragraph, and a link, which we'll use Flexbox to align.
  842. </p>
  843. <pre class="codeblock js-code-is-hidden">
  844. <code class="language-markup">
  845. &lt;!-- Split layout parent --&gt;
  846. &lt;div class="flex-split"&gt;
  847. &lt;!-- Child divs --&gt;
  848. &lt;div class="flex-split-left"&gt;
  849. &lt;!-- Putting the image in a div here is totally optional --&gt;
  850. &lt;div class="flex-split-image"&gt;
  851. &lt;img src="jake.png" /&gt;
  852. &lt;/div&gt;
  853. &lt;h3&gt;Jake the dog&lt;/h3&gt;
  854. &lt;p&gt;Etc etc etc&lt;/p&gt;
  855. &lt;a href="link.html"&gt;Read more&lt;/a&gt;
  856. &lt;/div&gt;
  857. &lt;div class="flex-split-right"&gt;
  858. &lt;!-- Etc, etc etc --&gt;
  859. &lt;/div&gt;
  860. &lt;/div&gt;
  861. </code>
  862. </pre>
  863. <h3>Step 2: Parent div</h3>
  864. <p>
  865. For the non-flexbox layout I'm using a minimum VH height (this won't work in IE8, so if you want it to work in IE8 you'll probably need to set a height with a unit which works in IE8). For this float layout, you're going to have to micromanage media queries as the screen gets narrower to deal with the content. We'll also need position:relative, so that we can absolutely position the child elements.
  866. </p>
  867. <p>
  868. For flexbox we add display:flex, once again indicating that we will use Flexbox to work with the child elements. You won't need to micromanage media queries here as Flexbox will just modify the container as the screen narrows.
  869. </p>
  870. <pre class="codeblock js-code-is-hidden">
  871. <code class="language-css">
  872. /* No flexbox layout with position relative and a minimum height */
  873. .no-flexbox .flex-split {
  874. position:relative;
  875. min-height:80vh;
  876. }
  877. /* Adding Flexbox, switch to rows and wrap at 48em */
  878. .flexbox .flex-split {
  879. display:flex;
  880. flex-direction:column;
  881. }
  882. @media all and (min-width:48em) {
  883. .flexbox .flex-split {
  884. flex-flow:row wrap;
  885. }
  886. }
  887. </code>
  888. </pre>
  889. <h3>Step 3: Child elements</h3>
  890. <p>
  891. For our non-flexbox layout we'll float the two child divs, give them a width of 50%, position them absolutely and anchor them to their sides.
  892. </p>
  893. <p>
  894. For our flexbox layout we'll just add a flex-basis of 50%, and pick a point where they collapse on a smaller screen and make that flex-basis 100% (and if you don't really need flexbox on the small screen you could just allow it to be displayed as a stacking block element).
  895. </p>
  896. <p>
  897. We need to change the flex-direction here to column to let Flexbox know to lay it out like a tube of vertical content. (although alternatively you could also use row with wrap, but it seemed to require more code to make work so I stuck with column). We also add display:flex to this element because we want to use Flexbox to position each of the content elements.
  898. </p>
  899. <pre class="codeblock js-code-is-hidden">
  900. <code class="language-css">
  901. /*
  902. For no flexbox - give the child elements a minimum height and position them top and bottom
  903. at 48ems make them float, otherwise just let the content fill the blocks on a small screen
  904. */
  905. @media all and (min-width:48em) {
  906. /* Common to both */
  907. .flex-split &gt; div {
  908. width:50%;
  909. }
  910. .no-flexbox .flex-split &gt; div {
  911. min-height:50vh;
  912. top:0;
  913. bottom:0;
  914. float:left;
  915. position:absolute;
  916. }
  917. /* Anchor to their respective sides */
  918. .no-flexbox .flex-split-left {
  919. left:0;
  920. }
  921. .no-flexbox .flex-split-right {
  922. right:0;
  923. }
  924. }
  925. /* For Flexbox - make the direct descendant divs content displayed in columns */
  926. .flexbox .flex-split &gt; div {
  927. display:flex;
  928. flex-direction:column;
  929. }
  930. </code>
  931. </pre>
  932. <h3>Step 4: Aligning the content with Flexbox</h3>
  933. <p>
  934. If, like me, you thought at this point that align-items: center would make the content center vertically, you'd be wrong. When you change the axis that Flexbox works off, the property you use to work with the vertical axis changes. The property that works now is justify-content.
  935. </p>
  936. <p>
  937. To center the content within the child divs, just add justify-content:center, and if you wanted you could also reorder, or align the content in any way you saw fit.
  938. </p>
  939. <pre class="codeblock js-code-is-hidden">
  940. <code class="language-css">
  941. /* Use flexbox to vertically center align */
  942. .flex-split &gt; div {
  943. justify-content:center;
  944. /* I needed to do this in IE10/11 to get it to horizontally center */
  945. align-items:center;
  946. }
  947. </code>
  948. </pre>
  949. <h2>Troubleshooting Flexbox</h2>
  950. <h3>
  951. Axis direction (flex direction)
  952. </h3>
  953. <p>
  954. When alignment doesn't seem to be doing anything, it's probably because you switched axis flex-direction from row to column. Align-items and Justify-content both rotate with the flex-direction. It took me putting borders around everything to discover this.
  955. </p>
  956. <h3>Flex items horizontal off the page</h3>
  957. <figure class="figure-contained">
  958. <img src="http://chriswrightdesign.com/experiments/img/screenshot_flexbox-overflowing.png" alt="Flexbox overflowing problem"/>
  959. <figcaption class="caption-below">Flex items horizontal off page</figcaption>
  960. </figure>
  961. <p>
  962. When items are horizontally overflowing the page, you probably need to add flex-wrap:wrap, or you're looking at the responsive imagery problem again.
  963. </p>
  964. <p>
  965. When I first started using Flexbox I was throwing Autoprefixer at things assuming that if Flexbox wasn't present that would be okay, it wasn't until I started testing on my older Android devices that I realized that even if a device was Flexbox capable, it didn't make it Flex-wrap capable - which was another reason I encountered this issue.
  966. </p>
  967. <h3>Inflexible imagery</h3>
  968. <p>
  969. One of the problems I came across when practicing flexbox was what happens when you use a flexible image within a flexbox container. This had to be my number one gripe - and it seemed to happen in EVERY browser.
  970. </p>
  971. <p>
  972. You might see this if you were setting your flex values in a row to something like flex:0 0 25%, and for some reason your rows are clearing on every 3rd item instead of every 4th item. Or worse your items are just flying off the page. It's because the image won't shrink. Applying flex-shrink won't help anything either.
  973. </p>
  974. <p>
  975. The problem is that while Flexbox seems to honor Max-width's maximum width, it doesn't recognize that a maximum-width:100% image is flexible and can scale down in size. That isn't entirely true. It's not that it doesn't recognize the image is scalable. This is actually because a block element will dictate the size of the image within. A flex element will try to resize itself to the size of the maximum image size.
  976. </p>
  977. <h4>The workaround</h4>
  978. <p>
  979. The workarounds for this are to either set the maximum width that you are okay with the image being in a unit other than a percentage. Or if you want it to be completely flexible - set it to 100%, with the obvious drawback of that image having the capability of going way too large.
  980. </p>
  981. <h3>Understanding space-around and space-between</h3>
  982. <p>
  983. I'm hoping my experiment has cleared it up a bit, it was a common one that got me. These are both calculated automatically, so if you want control don't use them.
  984. Space-around pins items from the centre and gives an even amount of spacing around any item within a flex container. So if there are two items, they'll both be equal distance from the sides and from each other. Think of it as inside-out.
  985. </p>
  986. <p>
  987. Space-between makes items pin to the outside of the container, then calculates an even amount of space between every item, think of it as outside-in.
  988. If you wanted that to be a fixed amount of padding or margin, then space-between isn't your choice, you should use flex-start.
  989. </p>
  990. <h3>
  991. How grow and shrink work
  992. </h3>
  993. <p>
  994. This one's a more basic mistake, I imagine most people wouldn't run into - if you don't want your flex items to become huge, don't grow them. The nth-child selector can help you organize this a bit better if you only want to grow the last item on every row.
  995. </p>
  996. <p>
  997. My basic rule is: I use grow if I want something to fill the space of a missing item, I use shrink if I want items to collapse to make way for new items.
  998. </p>
  999. <h3>
  1000. Items become many tiny columns
  1001. </h3>
  1002. <p>
  1003. Another fairly common one, you're looking at a row without row-wrap. Either make the container a column, or a row with row-wrap.
  1004. </p>
  1005. <h3>
  1006. IE 10/11 only: Wrapping too early, items too big
  1007. </h3>
  1008. <p>
  1009. Thanks to the Flex-bugs git repo I was able to debug this one pretty quick, I thought I'd mention it here because it was a HUGE spanner in the works for me. This is caused by using Flex-basis and Padding together. Flexbox won't accept the border-box box model properly, so to avoid this, use flex-basis auto and just use a standard width. The plus side of this is less code between floats and flexbox.
  1010. </p>
  1011. <h3>IE10/11 only: the heights are oddly collapsed</h3>
  1012. <p>
  1013. When I was creating my card pattern, I found the button was collapsing into the paragraphs - this is another bug documented on flexbox which caused me pain. As good as it feels to flex:1, just don't do it. Instead save yourself the panic by writing the full shorthand Flex:1 0 auto or flex:1 0 0.
  1014. </p>
  1015. <h3>FF: column-reverse and overflow-y</h3>
  1016. <p>
  1017. Thanks to Sean Curtis for helping me discover this one, it turns out it's already logged as a bug with Mozilla. If you use flex-direction:column-reverse with an element that uses overflow-y:auto, you won't see a scrollbar appear at all. It looks like this is in the process of being resolved.
  1018. </p>
  1019. <h3>
  1020. Well documented cross-browser bugs
  1021. </h3>
  1022. <p>
  1023. If you come across bugs that aren't listed here, it might be worthwhile checking out Philip Walton's <a href="http://philipwalton.com/articles/normalizing-cross-browser-flexbox-bugs/">normalizing cross-browser flexbox bugs</a> which points out a whole bunch that he came across that are specific to certain browsers. Or just check out the <a href="https://github.com/philipwalton/flexbugs">Git repo</a> which lists two of the bugs I mentioned here earlier. I constantly clashed with bugs 4, 5, and 7 from that list.
  1024. </p>
  1025. <h2>Add flexbox to your layouts</h2>
  1026. <p>
  1027. I'm keen to see how people add Flexbox to improve their layouts,
  1028. I am using Flexbox on production projects without the fear I used to have. I use it in small parts, testing small scale modules and working my way up. This strategy allows me to be certain that I'm not trashing a site for browsers that don't support it.
  1029. </p>
  1030. <p>
  1031. Having a strategy to approaching and implementing Flexbox is fairly crucial in successfully including it. Without a clear strategy going, starting from Flexbox and working backwards is akin to trying to dig yourself out of a hole.
  1032. </p>
  1033. <p>
  1034. If you're not all that confident with Flexbox, I'd recommend just having a play with recreating existing components - look at interesting layouts on gallery sites like <a href="http://www.dribbble.com">Dribbble</a>, <a href="http://www.paterntap.com">Pattern Tap</a>, or <a href="http://www.awwwards.com">Awwwards</a> and see how Flexbox can improve them. After the initial hours of headbutting your keyboard repeatedly, you'll see that it's actually pretty easy. Hopefully what I've written here will save you from the keyboard imprint on your face.
  1035. </p>
  1036. <p>
  1037. Got any great new applications of Flexbox that you're able to enhance from your standard layouts? Or are you already using Flexbox on your site? let me know! I'm interested in what people are doing with it.
  1038. </p>
  1039. </article>
  1040. </section>
  1041. <nav id="jumpto">
  1042. <p>
  1043. <a href="/david/blog/">Accueil du blog</a> |
  1044. <a href="http://chriswrightdesign.com/experiments/using-flexbox-today/">Source originale</a> |
  1045. <a href="/david/stream/2019/">Accueil du flux</a>
  1046. </p>
  1047. </nav>
  1048. <footer>
  1049. <div>
  1050. <img src="/static/david/david-larlet-avatar.jpg" loading="lazy" class="avatar" width="200" height="200">
  1051. <p>
  1052. Bonjour/Hi!
  1053. Je suis <a href="/david/" title="Profil public">David&nbsp;Larlet</a>, je vis actuellement à Montréal et j’alimente cet espace depuis 15 ans. <br>
  1054. Si tu as apprécié cette lecture, n’hésite pas à poursuivre ton exploration. Par exemple via les <a href="/david/blog/" title="Expériences bienveillantes">réflexions bimestrielles</a>, la <a href="/david/stream/2019/" title="Pensées (dés)articulées">veille hebdomadaire</a> ou en t’abonnant au <a href="/david/log/" title="S’abonner aux publications via RSS">flux RSS</a> (<a href="/david/blog/2019/flux-rss/" title="Tiens c’est quoi un flux RSS ?">so 2005</a>).
  1055. </p>
  1056. <p>
  1057. Je m’intéresse à la place que je peux avoir dans ce monde. En tant qu’humain, en tant que membre d’une famille et en tant qu’associé d’une coopérative. De temps en temps, je fais aussi des <a href="https://github.com/davidbgk" title="Principalement sur Github mais aussi ailleurs">trucs techniques</a>. Et encore plus rarement, <a href="/david/talks/" title="En ce moment je laisse plutôt la place aux autres">j’en parle</a>.
  1058. </p>
  1059. <p>
  1060. Voici quelques articles choisis :
  1061. <a href="/david/blog/2019/faire-equipe/" title="Accéder à l’article complet">Faire équipe</a>,
  1062. <a href="/david/blog/2018/bivouac-automnal/" title="Accéder à l’article complet">Bivouac automnal</a>,
  1063. <a href="/david/blog/2018/commodite-effondrement/" title="Accéder à l’article complet">Commodité et effondrement</a>,
  1064. <a href="/david/blog/2017/donnees-communs/" title="Accéder à l’article complet">Des données aux communs</a>,
  1065. <a href="/david/blog/2016/accompagner-enfant/" title="Accéder à l’article complet">Accompagner un enfant</a>,
  1066. <a href="/david/blog/2016/senior-developer/" title="Accéder à l’article complet">Senior developer</a>,
  1067. <a href="/david/blog/2016/illusion-sociale/" title="Accéder à l’article complet">L’illusion sociale</a>,
  1068. <a href="/david/blog/2016/instantane-scopyleft/" title="Accéder à l’article complet">Instantané Scopyleft</a>,
  1069. <a href="/david/blog/2016/enseigner-web/" title="Accéder à l’article complet">Enseigner le Web</a>,
  1070. <a href="/david/blog/2016/simplicite-defaut/" title="Accéder à l’article complet">Simplicité par défaut</a>,
  1071. <a href="/david/blog/2016/minimalisme-esthetique/" title="Accéder à l’article complet">Minimalisme et esthétique</a>,
  1072. <a href="/david/blog/2014/un-web-omni-present/" title="Accéder à l’article complet">Un web omni-présent</a>,
  1073. <a href="/david/blog/2014/manifeste-developpeur/" title="Accéder à l’article complet">Manifeste de développeur</a>,
  1074. <a href="/david/blog/2013/confort-convivialite/" title="Accéder à l’article complet">Confort et convivialité</a>,
  1075. <a href="/david/blog/2013/testament-numerique/" title="Accéder à l’article complet">Testament numérique</a>,
  1076. et <a href="/david/blog/" title="Accéder aux archives">bien d’autres…</a>
  1077. </p>
  1078. <p>
  1079. On peut <a href="mailto:david%40larlet.fr" title="Envoyer un courriel">échanger par courriel</a>. Si éventuellement tu souhaites que l’on travaille ensemble, tu devrais commencer par consulter le <a href="http://larlet.com">profil dédié à mon activité professionnelle</a> et/ou contacter directement <a href="http://scopyleft.fr/">scopyleft</a>, la <abbr title="Société coopérative et participative">SCOP</abbr> dont je fais partie depuis six ans. Je recommande au préalable de lire <a href="/david/blog/2018/cout-site/" title="Attention ce qui va suivre peut vous choquer">combien coûte un site</a> et pourquoi je suis plutôt favorable à une <a href="/david/pro/devis/" title="Discutons-en !">non-demande de devis</a>.
  1080. </p>
  1081. <p>
  1082. Je ne traque pas ta navigation mais mon
  1083. <abbr title="Alwaysdata, 62 rue Tiquetonne 75002 Paris, +33.184162340">hébergeur</abbr>
  1084. conserve des logs d’accès.
  1085. </p>
  1086. </div>
  1087. </footer>
  1088. <script type="text/javascript">
  1089. ;(_ => {
  1090. const jumper = document.getElementById('jumper')
  1091. jumper.addEventListener('click', e => {
  1092. e.preventDefault()
  1093. const anchor = e.target.getAttribute('href')
  1094. const targetEl = document.getElementById(anchor.substring(1))
  1095. targetEl.scrollIntoView({behavior: 'smooth'})
  1096. })
  1097. })()
  1098. </script>