learning to love absolute css positioning

30

Upload: huer1278ft

Post on 08-May-2015

11.034 views

Category:

Business


0 download

DESCRIPTION

Etan Marcotte from vertua.com @ SXSW2006

TRANSCRIPT

Page 1: Learning to love absolute CSS positioning
Page 2: Learning to love absolute CSS positioning

ethan marcottESXSW2006www.vertua.com

The Question

“”

Trying to move toward absolute positioning versus floats for layout.... I am trying to figure out if [you] have to always use a height

on the wrapper div. If I have text columns that have no specific

height it seems everything breaks at that point.

Shane Perran, graphicalwonder.com

Page 3: Learning to love absolute CSS positioning
Page 4: Learning to love absolute CSS positioning

ethan marcottESXSW2006www.vertua.com

Absolute Positioning

❖ It’s all about the x and the y (axes, that is)

❖ Treating parts of your document as distinct “layers”

❖ Use CSS to precisely place them upon a coordinate grid

Cake, yes? Let’s look at an example.

Page 5: Learning to love absolute CSS positioning

ethan marcottESXSW2006www.vertua.com

A new “positioning context”

div.photo { position: relative;}

p.caption { position: absolute; bottom: 9px;}

<div class="photo"> <p>Here’s a caption. Yay.</p> <img src="photo.jpg" alt="" /></div>

Page 6: Learning to love absolute CSS positioning

"Bottom-blindness"

Page 8: Learning to love absolute CSS positioning

position: relative;

Page 9: Learning to love absolute CSS positioning

position: absolute;width: [x];

position: absolute;width: [y]

margin-left: [x];margin-right: [y];

Page 10: Learning to love absolute CSS positioning
Page 11: Learning to love absolute CSS positioning
Page 12: Learning to love absolute CSS positioning
Page 13: Learning to love absolute CSS positioning
Page 14: Learning to love absolute CSS positioning

ethan marcottESXSW2006www.vertua.com

Remember <img align="left">?

Page 15: Learning to love absolute CSS positioning

ethan marcottESXSW2006www.vertua.com

The basics

img { float: left; }

Page 16: Learning to love absolute CSS positioning

ethan marcottESXSW2006www.vertua.com

The basics

img { float: right; }

Page 17: Learning to love absolute CSS positioning

ethan marcottESXSW2006www.vertua.com

Reflow, floats, and you

img { float: left; }

Page 18: Learning to love absolute CSS positioning

ethan marcottESXSW2006www.vertua.com

Restoring order to the flow

p.clear { clear: left; }

Page 20: Learning to love absolute CSS positioning

ethan marcottESXSW2006www.vertua.com

Okay, great. Kitty pictures. So?

❖ Floats can provide us with a more flexible layout model

❖ Clearing allows the components of our designs to become “context aware”

❖ Let’s view a simple example.

Page 21: Learning to love absolute CSS positioning

ethan marcottESXSW2006www.vertua.com

Marrying floats and positioning

Page 22: Learning to love absolute CSS positioning

ethan marcottESXSW2006www.vertua.com

The marvelous markup

<div class="person"> <div class="image"> <img src="photo.jpg" alt="" /> </div> <dl> <dt><a href="#">Durstan who?</a></dt> <dd> <ul>...</ul> </dd> </dl></div>

Page 23: Learning to love absolute CSS positioning

ethan marcottESXSW2006www.vertua.com

Getting our 2-column structure

Page 24: Learning to love absolute CSS positioning

ethan marcottESXSW2006www.vertua.com

Getting our 2-column structure

.person { clear: left;}

.person .image { float: left;}

Page 25: Learning to love absolute CSS positioning

ethan marcottESXSW2006www.vertua.com

One minor addition

<div class="person"> <div class="image"> <img src="photo.jpg" alt="" /> </div> <dl> <dt><a href="#">Durstan who?</a></dt> <dd> <ul>...</ul> </dd> </dl></div>

Page 26: Learning to love absolute CSS positioning

ethan marcottESXSW2006www.vertua.com

One minor addition

<div class="person"> <div class="image"> <img src="photo.jpg" alt="" /> </div> <dl> <dt><a href="#"><i></i>Durstan who?</a></dt> <dd> <ul>...</ul> </dd> </dl></div>

Page 27: Learning to love absolute CSS positioning

ethan marcottESXSW2006www.vertua.com

.person { position: relative;}

Layering the link

position: relative;

Page 28: Learning to love absolute CSS positioning

ethan marcottESXSW2006www.vertua.com

.person dt i { display: block; height: 160px; width: 160px; position: absolute; left: 0; top: 0;}

.person { position: relative;}

Layering the link

<i></i>