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

Understanding Page Flow

Understanding Page Flow

Reviewing floats, blocks, and inline blocks. Clearfixes, overflows, and a brief minute on positioning.

Avatar for Rob Riggs

Rob Riggs

April 21, 2013
Tweet

More Decks by Rob Riggs

Other Decks in Technology

Transcript

  1. Normal Document Flow • How a page is rendered without

    any styling • Browsers read content from top to bottom • Block level elements are displayed....? • Inline elements are displayed....? Sunday, April 21, 13
  2. Flow and Phrasing Content • Flow content - visibly determines

    page flow • typically block level elements • header, nav, footer, section, article, p • Phrasing content - mostly styles content • typically inline elements • i, em, span • http://www.html-5.com/tags/html-tag- list.html#flow-phrasing-content Sunday, April 21, 13
  3. Some are both... • a hyperlink, for example, can be

    both flow content and phrasing content • <a href=”one.html”><figure></figure></a> • <p>Here is the <a href=”doc.html”>document</a> Sunday, April 21, 13
  4. How to prep your flow • Write as little markup

    as possible • Work from the content out • http://www.markboultondesign.com/ • http://jsbin.com/ - excellent sandbox Sunday, April 21, 13
  5. Placeholder Info • Text • http://hipsteripsum.me/ • http://chrisvalleskey.com/fillerama/ • Images

    • http://placekitten.com/ • http://placedog.com/ Sunday, April 21, 13
  6. <!doctype html> <html lang="en"> <head> <title>Normal Document Flow</title> <style type="text/css">

    </style> </head> <body> <div class="container"> <h1>An Intro to Normal Document Flow.</h1> <figure class="photoGallery"> <img src="http://placekitten.com/g/100/200" alt="" /> <img src="http://placekitten.com/g/160/200" alt="" /> <img src="http://placekitten.com/g/220/200" alt="" /> <img src="http://placekitten.com/g/180/200" alt="" /> <img src="http://placekitten.com/g/240/200" alt="" /> <img src="http://placekitten.com/g/130/200" alt="" /> </figure> <article> <h2> Welcome to my Photo Gallery!</h2> <p>I am the man with no name, Zapp Brannigan! Bender, being God isn't easy. If you do too much, people get dependent on you, and if you do nothing, they lose hope. You have to use a light touch. Like a safecracker, or a pickpocket. Hey, guess what you're accessories to. Leela, Bender, we're going grave robbing. Also Zoidberg. Oh dear! She's stuck in an infinite loop, and he's an idiot! Well, that's love for you.</p> <p>Can I use the gun? Oh no! The professor will hit me! But if Zoidberg 'fixes' it&hellip; then perhaps gifts! Fry! Quit doing the right thing, you jerk! Who's brave enough to fly into something we all keep calling a death sphere? I haven't felt much of anything since my guinea pig died.</p> </article> </div> <footer> </footer> </body> </html> Markup Sunday, April 21, 13
  7. More CSS .container { width: 65%; margin:0 auto; background: #f2f2f2;

    } figure img { padding-left: 10px; } h1 { font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: #7caba9; padding-left: 10px; } article { background: #7caba9; color: #f2f2f2; padding: 10px; } Sunday, April 21, 13
  8. Floats • Elements are floated horizontally • Left, and right

    (no center... yet) • Floats will go as far as they can in the set direction • Floats disrupt the normal document flow • Following elements will flow around it... can be problematic Sunday, April 21, 13
  9. Web Inspectors • Chrome / Safari (CMD + ALT +

    I) • Firefox (Firebug) Sunday, April 21, 13
  10. Markup <header> <div class="logo">Stray Cat Design</div> <nav> <ul> <li><a href="#">Work</a></li>

    <li><a href="#">About</a></li> <li><a href="#">Blog</a></li> <li><a href="#">Contact</a></li> </ul> </nav> </header> Sunday, April 21, 13
  11. CSS header { background: red; } .logo { text-indent: -9999px;

    width: 272px; height: 271px; background: url ('http://www.backgroundsize.com/WebDev3/WeekOne/media/img/logo-stray-cat-designs.jpg') no-repeat; float: left; } nav { float: right; } Sunday, April 21, 13
  12. Where is the header? • No visible background color red

    • Since its children are floated, they are out of the normal document flow. • The header is left with a height of 0 pixels. • If you had any styling to the header, it would not appear. Sunday, April 21, 13
  13. Float recap • Parent container - float: left; • Children

    elements - float: left, right; • Parent’s following container - clear: both; Sunday, April 21, 13
  14. Review Markup header { background: red; float: left; width: 100%;

    } .logo { text-indent: -9999px; width: 272px; height: 271px; background: url ('http://www.backgroundsize.com/WebDev3/WeekOne/media/img/logo-stray-cat- designs.jpg’) no-repeat; float: left; } nav { float: right; } h1 { clear: both;} Sunday, April 21, 13
  15. Clearfix hack • Web standard nomenclature • Clears your floats,

    --AND-- • Parent container houses it children • Web community has evolved standard over time to remove the dreaded IE support • hack: an inelegant but effective solution to a computing problem Sunday, April 21, 13
  16. header { background: red; width: 100%; /* still necessary */

    } .clearfix:after { visibility: hidden; display: block; font-size: 0; content: " "; clear: both; height: 0; } .clearfix { display: inline-block; } Sunday, April 21, 13
  17. Clearfix, evolved • Goal to be semantically correct - Dan

    Cederholm • Discard support for older IE • Make content empty, remove all unnecessary properties Sunday, April 21, 13
  18. Group .group:after { content: ""; display: table; clear: both; }

    Note: you can remove the width from the header element Sunday, April 21, 13
  19. Inline-block • Hybrid display property • Make elements inline while

    having access to block level properties • width, height, margins, padding • Recognizes the space between elements, in your code, as if they were inline elements (i.e. &nbsp;) Sunday, April 21, 13
  20. Primary Navigation nav ul li { float: left; background: green;

    list-style-type: none; } -- OR -- nav ul li { display: inline-block; background: green; list-style-type: none; } Sunday, April 21, 13
  21. Now, try it with your image gallery figure img {

    float: left; } figure img { display: inline-block; } Sunday, April 21, 13
  22. • Clear float manually • Apply clearfix • or group,

    whatever you call it • add display: inline-block to figure css • --OR-- • add overflow:auto; to figure css (more to follow on overflow...) Sunday, April 21, 13
  23. All images are vertically aligned to the bottom, with spacing

    between the elements display: inline-block; Sunday, April 21, 13
  24. All images are vertically aligned to the middle, with spacing

    between the elements Sunday, April 21, 13
  25. What if I float my inline-blocks? figure img { float:

    left; display: inline-block; vertical-align: middle; } Sunday, April 21, 13
  26. Overflows • What happens if content overflows its container? •

    Properties: • visible - default • hidden • scroll • auto • inherit - inherits from parent Sunday, April 21, 13
  27. overflow: visible; height: 120px; easily avoidable by not setting a

    height, only do so when you plan to scroll mainly... Sunday, April 21, 13
  28. Overflow: scroll/auto • Compare webkit and mozilla Typically setting the

    overflow to scroll will give you both horizontal and vertical scrollbars, whether you need it or not.. Sunday, April 21, 13
  29. Considering the scroll • Can take up extra width in

    your UI • If you haven’t accounted for it, it can throw off your design Sunday, April 21, 13
  30. Overflow: auto, the clearer of floats • Add overflow: auto

    to parent container, housing the floated elements • You don’t need to define width like you do with inline-block (less code, targeted) • Excellent choice if you’re not expecting the container to function any other way (i.e. varying lengths of content, etc...) Sunday, April 21, 13
  31. header { background: red; overflow: auto; } .logo { text-indent:

    -9999px; width: 272px; height: 271px; background: url ('http://www.backgroundsize.com/WebDev3/WeekOne/media/img/logo-stray-cat-designs.jpg') no-repeat; float: left; } nav { float: right; } nav ul li { display: inline-block; background: green; list-style-type: none; } Sunday, April 21, 13
  32. Static positioning • Default, does not observe z-index or specified

    positioning • Positions itself relative to the normal document flow Sunday, April 21, 13
  33. Fixed positioning • Positioned relative to the browser window •

    It won’t move even if the browser window is scrolled • Very popular with ‘sticky’ navigation • Can be set by: • top, right, bottom, left • layered by z-index Sunday, April 21, 13
  34. Absolute positioning • Positioned relative to the document • Can

    also be positioned to a parent element if the parent is set to relative positioning • Can be set by: • top, right, bottom, left • layered by z-index Sunday, April 21, 13
  35. Relative positioning • Positioned relative to its normal position in

    the document flow • Primarily used as an anchor reference, for child elements to be absolutely positioned in reference to it, rather than the document window. • Can be set by: • top, right, bottom, left • layered by z-index Sunday, April 21, 13
  36. Homework • Bing up 5 HTML portfolio sites • Review

    their HTML and CSS • Look for floats, inline-blocks, and overflows • Compare and contrast • Tell me your preferences • Email report to me Sunday, April 21, 13
  37. But what if I can’t read their CSS? • It’s

    probably been minified, then, to optimize their site’s performance. • Open their CSS file, copy the contents and paste it here: • http://www.codebeautifier.com • Dont’ forget your Web inspector too! Sunday, April 21, 13