SlideShare a Scribd company logo
3
Most read
11
Most read
14
Most read
15
FLOATING AND POSITIONING
OVERVIEW
β€’ Understanding normal flow
β€’ Floating elements to the left and right
β€’ Clearing and containing floated elements
β€’ Text wrap shapes
β€’ Positioning: Absolute, relative, fixed
Normal Flow
In the normal flow, elements are laid out from top to bottom in
the order in which they appear in the source and from left to right
(in left-to-right reading languages).
Floating
float
Values: left, right, none
Moves an element as far as possible to the left or right and
allows the following content to wrap around it:
img { float: right; }
Floating (cont’d)
β€’ Floated elements are removed from the normal flow but
influence the surrounding content.
β€’ Floated elements stay within the content area of the element
that contains it.
β€’ Margins are always maintained (they don’t collapse) on all
sides of floated elements.
β€’ You must provide a width for a floated text element (because
default width is auto).
β€’ Elements don’t float higher than their reference in the source.
Clearing Floated Elements
clear
Values: left, right, both, none
Prevents an element from appearing next to a floated element
and forces it to start against the next available β€œclear” space
img {
float: left;
margin-right: .5em;
}
h2 {
clear: left;
margin-top: 2em;
}
(The h2 is β€œcleared” and starts below the floated element.)
Floating Multiple Elements
β€’ When you float multiple elements, browsers follow rules in the
spec to ensure they don’t overlap.
β€’ Floated elements will be placed as far left or right (as
specified) and as high up as space allows.
CSS Shapes (Text Wrap)
shape-outside
Values: none, circle(), ellipse(), polygon(), url(),
[margin-box | padding-box | content-box ]
Changes the shape of the text wrap to a circle or ellipse, a
complex path, or based on transparent areas in an image
shape-margin
Values: length, percentage
Specifies an amount of space to hold between the image and the
wrapped text
CSS Shapes (cont’d)
Positioning
position
Values: static, relative, absolute, fixed, sticky
Indicates that an element is to be positioned and specifies which
positioning method to use
top, right, bottom, left
Values: length, percentage, auto
Offset properties that provide the distance the element should be
moved away from that respective edge
Types of Positioning
β€’ Static: The default position in the flow
β€’ Relative: Moves the element relative to its original position
β€’ Absolute: Removes the element from the flow and places it
relative to the viewport or other containing element
β€’ Fixed: Element stays in one position relative to the viewport
β€’ Sticky: Element starts in the flow but stays fixed once it
scrolls to a particular position relative to the viewport
Relative Positioning
β€’ Moves the element relative to its original position
β€’ The space it originally occupied is preserved.
em {
position: relative;
top: 2em; /* moves it down */
left: 3em; /* moves it right */
background-color: fuchsia;
}
Absolute Positioning
β€’ Moves the element relative to the viewport or containing
block element
β€’ The space it originally occupied is closed up.
em {
position: absolute;
top: 2em;
left: 3em;
background-color: fuchsia;
}
Containing Blocks
β€’ A positioned element serves as a containing block (or
positioning context) for the elements it contains.
β€’ If a positioned element has an ancestor that has its position
set to relative, absolute, or fixed, then its position will
be relative to that containing block element.
β€’ If a positioned element is not contained within another
positioned element, then it is placed relative to the initial
containing block (the html element) and the viewport.
Containing Blocks (cont’d.)
p {
position: relative;
padding: 15px;
background-color: #F2F5D5;
border: 2px solid purple;
}
em {
position: absolute;
top: 2em;
left: 3em;
background-color: fuchsia;
}
The relatively positioned p element acts as a
containing block for the em element.
Specifying Position
β€’ Position can be specified in length measurements (like pixels)
or percentages.
β€’ The measurement moves it away from the positioning offset
property provided (i.e., top: 200px; moves the element
DOWN from the top edge).
β€’ Be careful not to overspecify. Two offset properties are usually
enough.
Stacking Order
z-index
Values: Number, auto

More Related Content

PPTX
Css Text Formatting
PDF
Dynamic CSS: Transforms, Transitions, and Animation Basics
PPTX
PPTX
Cascading style sheets (CSS)
PDF
HTML5: features with examples
PPTX
Css backgrounds
PPTX
CSS Positioning and Features of CSS3
PPT
Introduction to HTML
Css Text Formatting
Dynamic CSS: Transforms, Transitions, and Animation Basics
Cascading style sheets (CSS)
HTML5: features with examples
Css backgrounds
CSS Positioning and Features of CSS3
Introduction to HTML

What's hot (20)

PDF
Css properties
PPTX
Css Complete Notes
PPTX
Css types internal, external and inline (1)
PPTX
Chapter 14: Box Model
PPTX
CSS Animations & Transitions
PDF
Basic-CSS-tutorial
PPTX
CSS Transitions, Transforms, Animations
PDF
PPT
Css Ppt
PPTX
PPT
CSS Basics
PPT
Css lecture notes
PPTX
Css borders
PPT
PPT
Introduction to CSS Borders - Lesson 4
PPTX
Introduction to CSS
PPT
HTML
PPT
CSS ppt
PPT
Span and Div tags in HTML
Css properties
Css Complete Notes
Css types internal, external and inline (1)
Chapter 14: Box Model
CSS Animations & Transitions
Basic-CSS-tutorial
CSS Transitions, Transforms, Animations
Css Ppt
CSS Basics
Css lecture notes
Css borders
Introduction to CSS Borders - Lesson 4
Introduction to CSS
HTML
CSS ppt
Span and Div tags in HTML
Ad

Similar to Chapter 15: Floating and Positioning (20)

PPT
Css Positioning Elements
PPTX
Castro Chapter 11
PPT
Css advanced – session 4
PPTX
1 07-2-css floats-and_positioning
PDF
CSS3 Refresher
PDF
Exp13 write up
PPTX
Advanced CSS.pptx
PPTX
HTML and CSS part 3
PDF
CSS Positioning Elements.pdf
PPTX
HTML Block and Inline Elements
PPTX
Css training
PPTX
CSS_Day_Three (W3schools)
PDF
Web Design & Development - Session 3
PPTX
Cascading Style Sheets CSS
PPTX
Full Stack Development CSS_Layouts,Grid,FlexboxPPT.pptx
DOC
Art of css
PDF
Web Layout
PPTX
Css 101
PPT
animation for designing elements and botto
PPTX
Css position property
Css Positioning Elements
Castro Chapter 11
Css advanced – session 4
1 07-2-css floats-and_positioning
CSS3 Refresher
Exp13 write up
Advanced CSS.pptx
HTML and CSS part 3
CSS Positioning Elements.pdf
HTML Block and Inline Elements
Css training
CSS_Day_Three (W3schools)
Web Design & Development - Session 3
Cascading Style Sheets CSS
Full Stack Development CSS_Layouts,Grid,FlexboxPPT.pptx
Art of css
Web Layout
Css 101
animation for designing elements and botto
Css position property
Ad

More from Steve Guinan (20)

PPTX
Chapter 18: Transitions, Transforms, and Animation
PPTX
Chapter 17: Responsive Web Design
PPTX
Chapter 9: Forms
PPTX
Chapter 8: Tables
PPTX
Chapter 13: Colors and Backgrounds
PPTX
Chapter 12: CSS Part 2
PPTX
Chapter 11: Intro to CSS
PPTX
Chapter 23: Web Images
PPTX
Chapter 7: Images
PPTX
HubSpot Student Instructions
PPTX
Ch 6: Links
PPTX
Ch 5: Marking up Text
PPTX
Ch 3: Big Concepts
PPTX
Ch 2: How the Web Works
PPTX
Ch 1: Getting Started
PPTX
Intro to Web Design 6e Chapter 7
PPTX
Intro to Web Design 6e Chapter 6
PPTX
Intro to Web Design 6e Chapter 5
PPTX
Intro to Web Design 6e Chapter 4
PPTX
Intro to Web Design 6e Chapter 3
Chapter 18: Transitions, Transforms, and Animation
Chapter 17: Responsive Web Design
Chapter 9: Forms
Chapter 8: Tables
Chapter 13: Colors and Backgrounds
Chapter 12: CSS Part 2
Chapter 11: Intro to CSS
Chapter 23: Web Images
Chapter 7: Images
HubSpot Student Instructions
Ch 6: Links
Ch 5: Marking up Text
Ch 3: Big Concepts
Ch 2: How the Web Works
Ch 1: Getting Started
Intro to Web Design 6e Chapter 7
Intro to Web Design 6e Chapter 6
Intro to Web Design 6e Chapter 5
Intro to Web Design 6e Chapter 4
Intro to Web Design 6e Chapter 3

Recently uploaded (20)

PPTX
introduction about ICD -10 & ICD-11 ppt.pptx
PDF
Sims 4 Historia para lo sims 4 para jugar
PPTX
Slides PPTX World Game (s) Eco Economic Epochs.pptx
PPTX
innovation process that make everything different.pptx
PPTX
CSharp_Syntax_Basics.pptxxxxxxxxxxxxxxxxxxxxxxxxxxxx
PPTX
durere- in cancer tu ttresjjnklj gfrrjnrs mhugyfrd
PDF
Testing WebRTC applications at scale.pdf
PDF
β€œGoogle Algorithm Updates in 2025 Guide”
PDF
The Internet -By the Numbers, Sri Lanka Edition
Β 
DOCX
Unit-3 cyber security network security of internet system
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PPTX
cyber security Workshop awareness ppt.pptx
PDF
πŸ’° π”πŠπ“πˆ πŠπ„πŒπ„ππ€ππ†π€π πŠπˆππ„π‘πŸ’πƒ π‡π€π‘πˆ 𝐈𝐍𝐈 πŸπŸŽπŸπŸ“ πŸ’°
Β 
PPTX
PptxGenJS_Demo_Chart_20250317130215833.pptx
PPTX
artificial intelligence overview of it and more
PPTX
Funds Management Learning Material for Beg
PPTX
Digital Literacy And Online Safety on internet
PDF
LABUAN4D EXCLUSIVE SERVER STAR GAMING ASIA NO.1
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
introduction about ICD -10 & ICD-11 ppt.pptx
Sims 4 Historia para lo sims 4 para jugar
Slides PPTX World Game (s) Eco Economic Epochs.pptx
innovation process that make everything different.pptx
CSharp_Syntax_Basics.pptxxxxxxxxxxxxxxxxxxxxxxxxxxxx
durere- in cancer tu ttresjjnklj gfrrjnrs mhugyfrd
Testing WebRTC applications at scale.pdf
β€œGoogle Algorithm Updates in 2025 Guide”
The Internet -By the Numbers, Sri Lanka Edition
Β 
Unit-3 cyber security network security of internet system
WebRTC in SignalWire - troubleshooting media negotiation
Unit-1 introduction to cyber security discuss about how to secure a system
cyber security Workshop awareness ppt.pptx
πŸ’° π”πŠπ“πˆ πŠπ„πŒπ„ππ€ππ†π€π πŠπˆππ„π‘πŸ’πƒ π‡π€π‘πˆ 𝐈𝐍𝐈 πŸπŸŽπŸπŸ“ πŸ’°
Β 
PptxGenJS_Demo_Chart_20250317130215833.pptx
artificial intelligence overview of it and more
Funds Management Learning Material for Beg
Digital Literacy And Online Safety on internet
LABUAN4D EXCLUSIVE SERVER STAR GAMING ASIA NO.1
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...

Chapter 15: Floating and Positioning

  • 2. OVERVIEW β€’ Understanding normal flow β€’ Floating elements to the left and right β€’ Clearing and containing floated elements β€’ Text wrap shapes β€’ Positioning: Absolute, relative, fixed
  • 3. Normal Flow In the normal flow, elements are laid out from top to bottom in the order in which they appear in the source and from left to right (in left-to-right reading languages).
  • 4. Floating float Values: left, right, none Moves an element as far as possible to the left or right and allows the following content to wrap around it: img { float: right; }
  • 5. Floating (cont’d) β€’ Floated elements are removed from the normal flow but influence the surrounding content. β€’ Floated elements stay within the content area of the element that contains it. β€’ Margins are always maintained (they don’t collapse) on all sides of floated elements. β€’ You must provide a width for a floated text element (because default width is auto). β€’ Elements don’t float higher than their reference in the source.
  • 6. Clearing Floated Elements clear Values: left, right, both, none Prevents an element from appearing next to a floated element and forces it to start against the next available β€œclear” space img { float: left; margin-right: .5em; } h2 { clear: left; margin-top: 2em; } (The h2 is β€œcleared” and starts below the floated element.)
  • 7. Floating Multiple Elements β€’ When you float multiple elements, browsers follow rules in the spec to ensure they don’t overlap. β€’ Floated elements will be placed as far left or right (as specified) and as high up as space allows.
  • 8. CSS Shapes (Text Wrap) shape-outside Values: none, circle(), ellipse(), polygon(), url(), [margin-box | padding-box | content-box ] Changes the shape of the text wrap to a circle or ellipse, a complex path, or based on transparent areas in an image shape-margin Values: length, percentage Specifies an amount of space to hold between the image and the wrapped text
  • 10. Positioning position Values: static, relative, absolute, fixed, sticky Indicates that an element is to be positioned and specifies which positioning method to use top, right, bottom, left Values: length, percentage, auto Offset properties that provide the distance the element should be moved away from that respective edge
  • 11. Types of Positioning β€’ Static: The default position in the flow β€’ Relative: Moves the element relative to its original position β€’ Absolute: Removes the element from the flow and places it relative to the viewport or other containing element β€’ Fixed: Element stays in one position relative to the viewport β€’ Sticky: Element starts in the flow but stays fixed once it scrolls to a particular position relative to the viewport
  • 12. Relative Positioning β€’ Moves the element relative to its original position β€’ The space it originally occupied is preserved. em { position: relative; top: 2em; /* moves it down */ left: 3em; /* moves it right */ background-color: fuchsia; }
  • 13. Absolute Positioning β€’ Moves the element relative to the viewport or containing block element β€’ The space it originally occupied is closed up. em { position: absolute; top: 2em; left: 3em; background-color: fuchsia; }
  • 14. Containing Blocks β€’ A positioned element serves as a containing block (or positioning context) for the elements it contains. β€’ If a positioned element has an ancestor that has its position set to relative, absolute, or fixed, then its position will be relative to that containing block element. β€’ If a positioned element is not contained within another positioned element, then it is placed relative to the initial containing block (the html element) and the viewport.
  • 15. Containing Blocks (cont’d.) p { position: relative; padding: 15px; background-color: #F2F5D5; border: 2px solid purple; } em { position: absolute; top: 2em; left: 3em; background-color: fuchsia; } The relatively positioned p element acts as a containing block for the em element.
  • 16. Specifying Position β€’ Position can be specified in length measurements (like pixels) or percentages. β€’ The measurement moves it away from the positioning offset property provided (i.e., top: 200px; moves the element DOWN from the top edge). β€’ Be careful not to overspecify. Two offset properties are usually enough.