Slide 1

Slide 1 text

CSS CSS LAYOUTING

Slide 2

Slide 2 text

THE BOX MODEL THE BOX MODEL

Slide 3

Slide 3 text

Margin Padding Width Border

Slide 4

Slide 4 text

Works great... Don’t apply left, or right padding to elements with defined widths Floated elements with borders are wider than you think they are. Old IE has it’s own idea of a box model that is unlike any other with many bugs

Slide 5

Slide 5 text

CSS3 can normalize .selector { box-sizing: border-box; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; } Gets the box model to be more like IE6.

Slide 6

Slide 6 text

This is better... Borders, and horizontal paddings all all contained within the width. Supported by a majority of browsers, including the lovely IE8.

Slide 7

Slide 7 text

FLOATS FLOATS

Slide 8

Slide 8 text

.float { float: left; margin-right: 20px; margin-bottom: 20px; } .float .content A basic float

Slide 9

Slide 9 text

.float { float: left; width: 150px; margin-right: 20px; margin-bottom: 20px; } .float .content Another Common float .content { margin-left: 170px; }

Slide 10

Slide 10 text

Some caveats... Float without a width and the width of the interior content will be the width. Long text within a float requires that you set a width. Otherwise it’s 100%. A tall floated item must be cleared, or you will end up with floats within floats.

Slide 11

Slide 11 text

.float { float: right; margin-left: 20px; margin-bottom: 20px; } .float .content Uncleared floats .content .float

Slide 12

Slide 12 text

Clear your floats... No need to use extra markup to clear your floats. Self-clearing is the only way.

Slide 13

Slide 13 text

.selector { overflow: auto; *zoom: 1; } Self Clearing Floats .selector:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; }

Slide 14

Slide 14 text

Mixin Don’t use clearfix as a mixin in SASS or LESS. Use it as a class name and save.

Slide 15

Slide 15 text

.float { float: left; margin-left: -50px; margin-right: 20px; margin-bottom: 20px; } .float .content Crazy floats

Slide 16

Slide 16 text

Positioning Positioning

Slide 17

Slide 17 text

Things to remember... Absolutely positioned elements are positioned relative to the nearest relatively positioned element, or the body element if none. Fixed position elements are positioned relative to the body element every time.

Slide 18

Slide 18 text

Body Parent Child .parent { position: relative; } .child { position: fixed; top: 0; right: 0; left: 0; } Fixed Positioning

Slide 19

Slide 19 text

Body Parent Child .parent { position: relative; } .child { position: absolute; top: 0; left: 0; } Absolute Positioning

Slide 20

Slide 20 text

Z-index Z-index defines the layer that you want an element to appear on. IE6 & 7 have issues with z-index. Everyone else does it properly.

Slide 21

Slide 21 text

Z-INDEX Using z-index .selector:before { position: absolute; z-index: -1; top: -20px; opacity: 50; font-size: 75%; content: “Z-INDEX” } Z-INDEX Z-INDEX .selector:after { position: absolute; z-index: -2; top: -40px; opacity: 25; font-size: 50%; content: “Z-INDEX” }

Slide 22

Slide 22 text

Fin. Fin.