1 07-2-css floats-and_positioning

36
CSS Floats & Positioning Colin Gourlay & Kevin Vanderbeken

Upload: apnwebdev

Post on 18-Jan-2015

1.213 views

Category:

Technology


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: 1 07-2-css floats-and_positioning

CSS Floats & Positioning

Colin Gourlay & Kevin Vanderbeken

Page 2: 1 07-2-css floats-and_positioning

Today:

Floating Elements

Clearing Floated Elements

Page 3: 1 07-2-css floats-and_positioning

introduction

Page 4: 1 07-2-css floats-and_positioning

different boxes

Page 5: 1 07-2-css floats-and_positioning

block elements

<div>, <p>, etc.

I’m text inside a block element

So am I.

I’m in a block element too!

Page 6: 1 07-2-css floats-and_positioning

inline elements

<span>, <a>, etc.

I’m text inside an inline element So am I.

an inline element too!

I’m in

Page 7: 1 07-2-css floats-and_positioning

block and inline elements support the box model in

different ways

Page 8: 1 07-2-css floats-and_positioning

• The Width property wont do anything on inlines since they are defined by their content and run inline with other content.

• Margins are only possible on the left and right, not top and bottom.

• ...and other things left to your experimentation :-) 

Page 9: 1 07-2-css floats-and_positioning

In the CSS layout model, text elements are laid out from top to bottom in the

order in which they appear in the source, and from left to right.

Page 10: 1 07-2-css floats-and_positioning

When the window or containing element is resized, block elements

expand or contract to the new width.

block element

block element

block element

block element

block element

block element

Page 11: 1 07-2-css floats-and_positioning

When the window or containing element is resized, inline elements

reflow to fit. 

inline element inline element inline element

inline element inline

inline elementelement

Page 12: 1 07-2-css floats-and_positioning

elements don’t overlap or bunch up, they make room

for one another

Page 13: 1 07-2-css floats-and_positioning

floated elementsa.k.a

‘floats’

Page 14: 1 07-2-css floats-and_positioning

floats can be used to create:

multi-column layouts

navigation toolbars

table-like alignment(without tables)

and much, much moreTM

Page 15: 1 07-2-css floats-and_positioning

float: left;float: right;float: none;

Page 16: 1 07-2-css floats-and_positioning

things you should know about floated elements

Page 17: 1 07-2-css floats-and_positioning

a floated element is like an island in a stream

I’m a block element that is beside an image that has been floated to theright. My contents will wrap around the image.

Page 18: 1 07-2-css floats-and_positioning

floats stay in the content area of the containing element

this isn’t possible

Page 19: 1 07-2-css floats-and_positioning

margins are maintained

I’m a block element that is beside an image that has been floated to theright. My contents will wrap around the image.

img { float: right; margin-left: 5px; margin-right: 5px; }

Page 20: 1 07-2-css floats-and_positioning

always provide a width for floated elements

I’m a block element that is beside an paragraph that has been floated to the right. My contents will wrap around the paragraph.

p.floatRight { float: right; margin: 5px; width: 120px; }

I’m a paragraph element, floated to the right, with a defined width

Page 21: 1 07-2-css floats-and_positioning

floated inline elements behave as block elements

Page 22: 1 07-2-css floats-and_positioning

elements do not float higher than their reference in the

source

Page 23: 1 07-2-css floats-and_positioning

you can float multiple elements

Because I am beside two floated

elements (one left, one right), I wrap around both of them.

Page 24: 1 07-2-css floats-and_positioning

there is one noticeable side effect of using floats...

Page 25: 1 07-2-css floats-and_positioning
Page 26: 1 07-2-css floats-and_positioning

what we actually want to see is this...

Page 27: 1 07-2-css floats-and_positioning
Page 28: 1 07-2-css floats-and_positioning

to achieve this effect, we need to make use of

clearing

Page 29: 1 07-2-css floats-and_positioning

clearing floated elements

Page 30: 1 07-2-css floats-and_positioning

clear: left;clear: right;clear: both;

Page 31: 1 07-2-css floats-and_positioning

clear: left;The left value starts the

element below any elements that have been

floated to the left

Page 32: 1 07-2-css floats-and_positioning

clear: right;Similarly, the right value

makes the element clear all floats on the right edge of

the containing block

Page 33: 1 07-2-css floats-and_positioning

clear: both; If there are multiple floated

elements, and you want to be sure an element starts below

all of them, use the both value to clear floats on both

sides

Page 34: 1 07-2-css floats-and_positioning

My position is governed by the floated elements to the left. I have not been cleared in any way.

I have been cleared, so I start below the floated elements.

Page 35: 1 07-2-css floats-and_positioning

next week...

Page 36: 1 07-2-css floats-and_positioning

CSS Positioning

&

CSS Grid Systems