Top Banner
CSS Layout
25

CSS Layout - University of Colorado Bouldercreative.colorado.edu/atlas2200/pdf/week7-tech-css-layout.pdf · handling multi-column layout kind of a css “hack” will be replaced

May 24, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CSS Layout - University of Colorado Bouldercreative.colorado.edu/atlas2200/pdf/week7-tech-css-layout.pdf · handling multi-column layout kind of a css “hack” will be replaced

CSS Layout

Page 2: CSS Layout - University of Colorado Bouldercreative.colorado.edu/atlas2200/pdf/week7-tech-css-layout.pdf · handling multi-column layout kind of a css “hack” will be replaced

we used to hack html to force layout

transparent gif

frame layout

html table layout

Page 3: CSS Layout - University of Colorado Bouldercreative.colorado.edu/atlas2200/pdf/week7-tech-css-layout.pdf · handling multi-column layout kind of a css “hack” will be replaced

CSS Positioning

Page 4: CSS Layout - University of Colorado Bouldercreative.colorado.edu/atlas2200/pdf/week7-tech-css-layout.pdf · handling multi-column layout kind of a css “hack” will be replaced

the FLOW

block elements (flow top to bottom) inline elements (flow left to right)

Static Positioning

text flows left to right

Page 5: CSS Layout - University of Colorado Bouldercreative.colorado.edu/atlas2200/pdf/week7-tech-css-layout.pdf · handling multi-column layout kind of a css “hack” will be replaced

OUT of the FLOW

top, left width, height

independent layers

NOT RESPONSIVE

Absolute Positioning(0, 0)

width

heigh

t

top

left

overlap(z-index)

Page 6: CSS Layout - University of Colorado Bouldercreative.colorado.edu/atlas2200/pdf/week7-tech-css-layout.pdf · handling multi-column layout kind of a css “hack” will be replaced

still in the FLOW

top, left

OFFSET elements

z-index

Relative Positioning

Page 7: CSS Layout - University of Colorado Bouldercreative.colorado.edu/atlas2200/pdf/week7-tech-css-layout.pdf · handling multi-column layout kind of a css “hack” will be replaced

OUT of the FLOW

glued to background

also z-index

Fixed Positioningfixed

Page 8: CSS Layout - University of Colorado Bouldercreative.colorado.edu/atlas2200/pdf/week7-tech-css-layout.pdf · handling multi-column layout kind of a css “hack” will be replaced

z-indexinteger

sets layer order

overrides default order

z-index: 10;

-10

10

93

Page 9: CSS Layout - University of Colorado Bouldercreative.colorado.edu/atlas2200/pdf/week7-tech-css-layout.pdf · handling multi-column layout kind of a css “hack” will be replaced
Page 10: CSS Layout - University of Colorado Bouldercreative.colorado.edu/atlas2200/pdf/week7-tech-css-layout.pdf · handling multi-column layout kind of a css “hack” will be replaced
Page 11: CSS Layout - University of Colorado Bouldercreative.colorado.edu/atlas2200/pdf/week7-tech-css-layout.pdf · handling multi-column layout kind of a css “hack” will be replaced

GO with the FLOW (static positioning)

By default already RESPONSIVE

until we mess it up with multi-column layout…

STILL the best positioning for responsive design

Page 12: CSS Layout - University of Colorado Bouldercreative.colorado.edu/atlas2200/pdf/week7-tech-css-layout.pdf · handling multi-column layout kind of a css “hack” will be replaced

static add widths floats flexbox

css grids

Page 13: CSS Layout - University of Colorado Bouldercreative.colorado.edu/atlas2200/pdf/week7-tech-css-layout.pdf · handling multi-column layout kind of a css “hack” will be replaced

Floats

was industry standard method for handling multi-column layout

kind of a css “hack”

will be replaced by flexbox and css grids

Page 14: CSS Layout - University of Colorado Bouldercreative.colorado.edu/atlas2200/pdf/week7-tech-css-layout.pdf · handling multi-column layout kind of a css “hack” will be replaced

Floats are for images

text wraps around image

float: left

floated object is in the”flow” the rest of the block is up for grabs

Page 15: CSS Layout - University of Colorado Bouldercreative.colorado.edu/atlas2200/pdf/week7-tech-css-layout.pdf · handling multi-column layout kind of a css “hack” will be replaced
Page 16: CSS Layout - University of Colorado Bouldercreative.colorado.edu/atlas2200/pdf/week7-tech-css-layout.pdf · handling multi-column layout kind of a css “hack” will be replaced

float: left; float: right;

two column layout

(width) (width)

Page 17: CSS Layout - University of Colorado Bouldercreative.colorado.edu/atlas2200/pdf/week7-tech-css-layout.pdf · handling multi-column layout kind of a css “hack” will be replaced

float: left;

three column layout

float: left; float: left;

Page 18: CSS Layout - University of Colorado Bouldercreative.colorado.edu/atlas2200/pdf/week7-tech-css-layout.pdf · handling multi-column layout kind of a css “hack” will be replaced

float: left; float: right;

Page 19: CSS Layout - University of Colorado Bouldercreative.colorado.edu/atlas2200/pdf/week7-tech-css-layout.pdf · handling multi-column layout kind of a css “hack” will be replaced

float: left; float: right;

clearfix

.clearfix:after { display: table; content: " "; clear: both; }

.left {float: left;}

.right {float: right;}

<parent class=“clearfix”> <child class=“left”>…</child> <child class=“right”>…</child> </parent>

Page 20: CSS Layout - University of Colorado Bouldercreative.colorado.edu/atlas2200/pdf/week7-tech-css-layout.pdf · handling multi-column layout kind of a css “hack” will be replaced

float onfloat property

float left and right for 2 columns

float all left for 3+ columns

widths

clearfix

Page 21: CSS Layout - University of Colorado Bouldercreative.colorado.edu/atlas2200/pdf/week7-tech-css-layout.pdf · handling multi-column layout kind of a css “hack” will be replaced

box-sizing: content-box;

contentpadding

border

margin

300px+5px +5px

+5px

+5px

+2px

2px

2px

2px

how browsersrender the box model(default)

content + padding + border = width

width = 314px

Page 22: CSS Layout - University of Colorado Bouldercreative.colorado.edu/atlas2200/pdf/week7-tech-css-layout.pdf · handling multi-column layout kind of a css “hack” will be replaced

box-sizing: border-box;

contentpadding

border

margin

286px+5px +5px

+5px

+5px

+2px

2px

2px

2px

IE oops = good

width includes padding and border

width = 300px

won’t break layout 300px

Page 23: CSS Layout - University of Colorado Bouldercreative.colorado.edu/atlas2200/pdf/week7-tech-css-layout.pdf · handling multi-column layout kind of a css “hack” will be replaced

css reset*, *:before, *:after { margin: 0; padding: 0; box-sizing: border-box; }

Page 24: CSS Layout - University of Colorado Bouldercreative.colorado.edu/atlas2200/pdf/week7-tech-css-layout.pdf · handling multi-column layout kind of a css “hack” will be replaced

Flexbox

css box positioning designed for responsive

browser support - finally! (can i use)

Page 25: CSS Layout - University of Colorado Bouldercreative.colorado.edu/atlas2200/pdf/week7-tech-css-layout.pdf · handling multi-column layout kind of a css “hack” will be replaced

flexbox codeadd flex to parent element

how it should handle spaces between

which direction it should flex (flow)

give children widths! (px or %)

main { display: flex; justify-content: space-around; flex-flow: row; }

main section { width: 45%; background: white; border: solid 1px black; }