Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Responsive Webdesign: Neue Möglichkeiten und Freiheiten mit dem CSS3-Flexbox-Modell

Responsive Webdesign: Neue Möglichkeiten und Freiheiten mit dem CSS3-Flexbox-Modell

New opportunities with the CSS3-Flexbox-Modell. The Slides are in German.

Peter Rozek

June 04, 2014
Tweet

More Decks by Peter Rozek

Other Decks in Programming

Transcript

  1. Elemente lassen in der Höhe, als auch in der Breite

    nach unterschiedlichsten Verhältnissen anpassen.
  2. Für komplexere Lösungen wie z.B. “Equal Height Columns” oder “Vertical

    Alignment” muss man tief in die Trickkiste greifen.
  3. {css} .content { width: 60%; float: left; background: #fff; }

    .sidebar { width: 20%; float: left; } .footer { clear: both; float: none; } Ausrichtung: Design: #content, #footer, .primary, .secondary { padding: 3% 5%; } #header, #footer { background: #0e212e; color: #fff; } .secondary { background: #bbc4c9; } .primary { background: #5f6d7a; }
  4. .content { float: left; } .content, .content:before { width: 60%;

    } .content:before { content: ''; position: absolute; top: 0; bottom: 0; z-index: -1; left: 0; background: #fff; } .primary, .primary:before { width: 20%; } .primary:before { content: ''; position: absolute; top: 0; bottom: 0; z-index: -1; left: 60%; background-color: #5f6673; } .secondary, .secondary:before { width: 20%; } .secondary:before { content: ''; position: absolute; top: 0; bottom: 0; z-index: -1; left: 80%; background-color: #434750; } {css} .sidebar { float: left; } .wrapper { position: relative; overflow: hidden; } .footer { clear: both; float: none; }
  5. <html> <div class="page"> <header>…</header> <div class="wrapper"> <main class="content" data-match-height=„items-a">...</main> <aside

    class="sidebar primary" data-match-height=„items-a">...</aside> <aside class="sidebar secondary" data-match-height=„items-a">...</aside> </div> <footer>…</footer> </div> data Attribute
  6. {css} .content { width: 60%; float: left; background: #fff; }

    .sidebar { width: 20%; float: left; } .footer { clear: both; float: none; } Ausrichtung: Design: #content, #footer, .primary, .secondary { padding: 3% 5%; } #header, #footer { background: #0e212e; color: #fff; } .secondary { background: #bbc4c9; } .primary { background: #5f6d7a; }
  7. <html> <div class="page"> <header>…</header> <div class="wrapper"> <main class="content">...</main> <aside class="sidebar

    primary">...</aside> <aside class="sidebar secondary">...</aside> </div> <footer>…</footer> </div>
  8. <html> <div class="page"> <header>…</header> <div class="wrapper"> <main class="content">...</main> <aside class="sidebar

    primary">...</aside> <aside class="sidebar secondary">...</aside> </div> <footer>…</footer> </div> {css} .wrapper { display: flex; } wrapper = flex container content und sidebar = flex items
  9. 1. Floats? Die brauchen wir nicht. ! 2. Layouts, die

    zuvor eine Herausforderung waren, sind nun verständlicher. ! 3. Wir können wirklich flexible Layouts erstellen und die Berechnungen macht der Browser.
  10. Properties Elternelement (flex container) Properties Kindelemente display flex-direction flex-wrap flex-flow

    align-items justify-content align-content order flex-grow flex-shrink flex-basis flex (flex items) (flex items) (flex items)
  11. Aufbau Flex Container main axis main start main end cross

    axis cross start cross end flex items
  12. flex-direction: row; 4 3 2 1 1 2 3 4

    4 3 2 1 1 2 3 4 flex-direction: row-reverse; flex-direction: column; flex-direction: column-reverse; Syntax:
  13. Legt fest, ob die Elemente in einem Flexbox- Container auf

    einer Linie liegen, oder bei bedarf auf mehrere Zeilen verteilt werden können. flex-wrap: nowrap wrap wrap-reverse
  14. Syntax: flex-wrap: nowrap; flex-wrap: wrap; flex-wrap: wrap-reverse; Die flexiblen Elemente

    liegen alle in derselben Reihe, auch wenn dazu der Platz fehlt. Die flexiblen Elemente können sich wenn nötig innerhalb des Containers in mehrere Zeilen aufteilen (nach unten). Die flexiblen Elemente können sich wenn nötig innerhalb des Containers in mehrere Zeilen aufteilen (nach oben).
  15. Legt fest, wo die Elemente in einem Flexbox- Container positioniert

    sind, oder welchen Abstand sie zueinander haben. align-content: flex-start flex-end center space-between space-around stretch
  16. Syntax: align-content: flex-start; 1 2 3 4 5 6 1

    2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 align-content: flex-end; align-content: center; align-content: space-between; align-content: space-around; align-content: stretch;
  17. Die Kurzschreibweise flex fasst die Eigenschaften flex-grow, flex-shrink und flex-basis

    zusammen. syntax aus: „flex-grow“ „flex-shrink“ „flex-basis“ flex
  18. .flexitem { flex: 1 1 100px; } flex-shrink flex-basis flex-grow

    Eigenschaft flex gibt den Flex-items flexible Ausmaße mit.
  19. .flex-container { display: flex; } ! .main { flex: 40%

    1 2; } ! .primary { flex: 20% 1 1; } ! .secondary { flex: 20% 2 1; }
  20. .flex-container { display: flex; } ! .main { order: 2;

    } ! .primary { order: 1; } ! .secondary { order: 3; }
  21. <html> Ausgangslage HTML: <div class=„page flex-container"> <header>…</header> <main class=„content“> <div

    class=„box“> … </div> … </main> <aside class="sidebar primary">...</aside> <aside class="sidebar secondary“> <div class=„box“> … </div> … </aside> <footer>…</footer> </div>
  22. {css} ..flex-container { display: flex; flex-flow: row wrap; } #header

    { order: 1; } .content { display: flex; flex-flow: column wrap; order: 2; } .primary { order: 4; } .secondary { display: flex; flex-flow: column reverse; order: 3; } #footer { order: 5; } Basis:
  23. {css} Responsive: @media screen and (min-width: 48em) { .content {

    display: flex; flex-flow: row wrap; width: 75%; } .content .box { padding: 0; margin: 0 1em; flex: 1 1 30%; } .primary { width: 25%; padding: 1em 4.833%; order: 3; } .secondary { flex-direction: row; justify-content: space around; padding: 3% 4%; } .secondary .box { padding: 0; margin: 0 1em; } }
  24. „Multiscreen is about developing a single application for multiple interfaces

    – one for each screen type: smartphone, tablet, desktop, and television.“ Ridley Marx
  25. John Allsopp, A dao of webdesign: http://alistapart.com/article/dao „It is the

    nature of the web to be flexible, and it should be our role as designers and developers to embrace this flexibility, and produce pages which, by being flexible, are accessible to all. The journey begins by letting go of control, and becoming flexible.“
  26. Ja

  27. 11.0 29.0 35.0 7.0* 21.0 Supported teilweise Supported nicht Supported

    Browsersupport Desktop http://caniuse.com/flexbox * benötigt Vendor-Präfix
  28. 11.0 28.0 34.0 7.0* 20.0 10.0* 27.0 33.0 6.1* 19.0

    9.0 26.0 32.0 6.0* 18.0 8.0 24.0 31.0 5.1* 17.0 Supported teilweise Supported nicht Supported 29.0 35.0 21.0 http://caniuse.com/flexbox * benötigt Vendor-Präfix
  29. 7.0* 5.0-7.0 4.4 10.0* 21.0 35.0 29.0 10.0* Supported teilweise

    Supported nicht Supported Browsersupport Mobile * benötigt Vendor-Präfix iOS Mini Mobile Andriod Andriod http://caniuse.com/flexbox
  30. 7.0* 5.0-7.0 4.4 10.0* 16.0 35.0 29.0 10.0* 6.0-6.1* 4.2-4.3*

    7.0* 12.1 5.0-5.1* 4.1* 12.0 4.2-4.3* 4.0* 11.5 Supported teilweise Supported nicht Supported 4.0-4.1* 3.0* iOS Mini Mobile Andriod Andriod 26.0* 33.0 http://caniuse.com/flexbox 21.0 * benötigt Vendor-Präfix
  31. .selektor { display: -webkit-box; ! display: -moz-box; ! display: -ms-flexbox;

    ! display: -webkit-flex; ! display: flex; ! } /* NEW: IE11, Chrome 29+, Opera 12.1+, Firefox 22+ */ /* OLD: Safari, iOS, Android browser, older WebKit browsers. */ /* NEW, Chrome 21–28, Safari 6.1+ */ /* MID: IE 10 */ /* OLD: Firefox (buggy) */ {css}
  32. @mixin flexbox { display: -webkit-box; display: -webkit-flex; display: -moz-flex; display:

    -ms-flexbox; display: flex; } ! .flexbox { @include flexbox; } {scss}
  33. {JS} <script> Modernizr.addTest(’ meinflexbox ‘, function(){ return Modernizr.testAllProps (’ eigenschaft

    ’); }); </script> Text ob bestimmte Eigenschaften unterstützt werden. Die Klasse „meinflexbox“ wird beim html Start-Tag ergänzt.
  34. Flexie ist ein JavaScript Polyfill für die Flexbox, berücksichtigt aber

    den alten Standard. Flexie http://flexiejs.com/
  35. Mach es anders als andere (es erwarten). Selbst wenn Deine

    Aktivität in eine falsche Richtung geht, erhältst Du wertvolle Informationen daraus. Jeder Fehler ist der Beginn einer neuen Idee.