CSS
POSITIONING
(PUTTING HTML IN ITS PLACE)
CSS POSITIONING (PUTTING HTML IN ITS PLACE) BLOCK VS. INLINE H1 - - PowerPoint PPT Presentation
CSS POSITIONING (PUTTING HTML IN ITS PLACE) BLOCK VS. INLINE H1 PAGE H2 P FLOW P P BLOCK VS. INLINE H1 width: 300px STILL DOWN HERE H2 P P P BLOCK-LEVEL ELEMENTS INSIST ON TAKING UP THEIR OWN LINE. ON THE OTHER HAND, INLINE
POSITIONING
(PUTTING HTML IN ITS PLACE)
BLOCK VS. INLINE
H1
H2 P P PPAGE FLOW
BLOCK VS. INLINE
H1
H2 P P PSTILL DOWN HERE width: 300px
BLOCK-LEVEL ELEMENTS INSIST ON TAKING UP THEIR OWN LINE.
ON THE OTHER HAND, INLINE ELEMENTS...
INLINE ELEMENTS
P Before they sold out DIY Cosby sweater, master cleanse sartorial american apparel +1 pour-over ennui raw denim pork belly gastropub. Vegan skateboard, craft beer DIY wayfarers high life photo booth gastropub Austin. Narwhal cliche umami blog. Cardigan street art high life kale chips, PINLINE ELEMENTS
P Before they sold out DIY Cosby sweater, master cleanse sartorial american apparel +1 pour-over ennui raw denim pork belly gastropub. Vegan skateboard, craft beer DIY wayfarers high life photo booth gastropub Austin. Narwhal cliche umami blog. Cardigan street art high life kale chips, P<a>
INLINE ELEMENTS
P Before they sold out DIY Cosby sweater, master cleanse sartorial american apparel +1 pour-over ennui raw denim pork belly gastropub. Vegan skateboard, craft beer P<img> <em> <u>
<div>’S YOUNGER, CUTER, INLINE BROTHER
<span>
.dropcap { font-size: 48px; float: left; }
SPAN
.acroynm { font-size: .8em; text-transform: uppercase; }
SO, EVERYTHING IS EITHER BLOCK-LEVEL OR INLINE. THAT SEEMS PRETTY EFFIN’ LIMITING.
h2 { display: inline; }
DISPLAY
img { display: block; }
THE BOX MODEL
WIDTH HEIGHT Pork belly etsy beard fixie. Chillwave banh mi american apparel, trust fund bushwick skateboard viral. Wolf messenger bag twee, raw denim terry richardson forage selvage single-origin coffee. Food truck raw denim fixie pinterest chillwave mumblecore. American apparel photo booth truffaut pour-over high life pop-up. MARGIN PADDING BORDERTHE BOX MODEL
TOTAL WIDTH = 2×PADDING + 2×BORDER + WIDTH HEIGHT Pork belly etsy beard fixie. Chillwave banh mi american apparel, trust fund bushwick skateboard viral. Wolf messenger bag twee, raw denim terry richardson forage selvage single-origin coffee. Food truck raw denim fixie pinterest chillwave mumblecore. American apparel photo booth truffaut pour-over high life pop-up. MARGIN PADDING BORDERTHE NEWER, BETTER WAY
BOX-SIZING: BORDER-BOX
Pork belly etsy beard fixie. Chillwave banh mi american apparel, trust fund bushwick skateboard viral. Wolf messenger bag twee, raw denim terry richardson forage selvage single-BOX-SIZING: BORDER-BOX
* {
box-sizing: border-box; }
BOX-SIZING: BORDER-BOX
CSS RESET
CONTAINERS
<body> <div class=“container”> <h1>WELCOME TO CRYING KITTENS</h1> <p>I LOVE TO SEE KITTENS CRY ALL DAY</p> <img src=“sadkitten.jpg”> </div> </body>CONTAINERS
.container { width: 900px; margin: 100px auto; }
.container { width: 900px; margin: 100px auto; }
CONTAINERS
CENTERS CONTAINER IN WINDOW
.container { width: 900px; margin: 100px auto; }
CONTAINERS
WHAT HAPPENS IF WE DON’T INCLUDE A WIDTH?
CONTAINERS
<body> <section class=“sidebar”> <h1>SIDEBAR CONTENT</h1> <p>THIS WILL BE ON THE LEFT SIDE</p> </section> <section class=“main”> <h1>MAIN CONTENT</h1> <p>THIS WILL BE IN THE MAIN COLUMN</p> <img src=“sadkitten.jpg”> </section> </body>FLOAT & CLEAR
BEST FOR:
COMPOSITION RELIES ON THE ELEMENT
FLOAT & CLEAR
h2 { float: left; width: 300px; }
FLOAT & CLEAR
p { clear: both; }
.sidebar { float: left; width: 130px; }
FLOAT & CLEAR
.main { margin-left: 150px; }
NOTES ON FLOATS:
THROUGH” FLOATED ELEMENTS
UNLESS YOU STATE A WIDTH AND HEIGHT
FLOAT & CLEAR
FLOATS DON’T TAKE UP SPACE IN THE NORMAL WAY, SO HOW CAN WE GET BOXES TO HOLD THEM?
CLEARFIX!
FLOAT & CLEAR
PROTIP!
.clearfix:before, .clearfix:after { content: " "; display: table; } .clearfix:after { clear: both; } .clearfix { *zoom: 1; }
CLEARFIX
PROTIP!
CLEARFIX
<div class=“container”> <div class=“floatleft”>Gallery Item #1</div> <div class=“floatleft”>Gallery Item #2</div> <div class=“floatleft”>Gallery Item #3</div> <div class=“floatleft”>Gallery Item #4</div> <div class=“floatleft”>Gallery Item #5</div> </div>CLEARFIX
GALLERY ITEM #1 GALLERY ITEM #2 GALLERY ITEM #3 GALLERY ITEM #4 GALLERY ITEM #5 #containerCLEARFIX
<div class=“container clearfix”> <div class=“floatleft”>Gallery Item #1</div> <div class=“floatleft”>Gallery Item #2</div> <div class=“floatleft”>Gallery Item #3</div> <div class=“floatleft”>Gallery Item #4</div> <div class=“floatleft”>Gallery Item #5</div> </div>CLEARFIX
GALLERY ITEM #1 GALLERY ITEM #2 GALLERY ITEM #3 GALLERY ITEM #4 GALLERY ITEM #5 #container.badge { position: absolute; }
POSITION
.nav { position: fixed; } .container { position: relative; }
H1
H2 P P PPAGE FLOW RELATIVE POSITIONING
ABSOLUTE POSITIONING
BEST FOR:
ORNAMENTS
TO BE EXPLICITLY IN ONE PLACE
H1
H2 P P PABSOLUTE POSITIONING
H1
H2 P P PABSOLUTE POSITIONING
H1
H2 P P PABSOLUTE POSITIONING
H1
H2 P P PWHEREVER THE F*@# YOU WANT IT. ABSOLUTE POSITIONING
H1
H2 P P PPAGE FLOW
ABSOLUTE POSITIONING
WHY DON’T WE JUST ALWAYS USE ABSOLUTE POSITIONING?
ABSOLUTE POSITIONING
NOT GOOD FOR:
.header { position: absolute; top: 40px; right: 10px; }
ABSOLUTE POSITIONING
.header { position: absolute; top: 40px; right: 10px; z-index: 100; }
ABSOLUTE POSITIONING PROTIP!
.header { position: absolute; top: 40px; right: 10px; left: 10px; bottom: 10px; }
ABSOLUTE POSITIONING PROTIP!
CONTAINED ABSOLUTES
.header { position: absolute; top: 40px; right: 10px; } .container { position: relative; margin: 40px auto; }
ABSOLUTE POSITIONING = TOP, LEFT, RIGHT, BOTTOM RELATIVE POSITIONING = MARGINS
SPACING
PROTIP!
PROTIP!
AND IT ONLY GETS MORE COMPLICATED