SlideShare a Scribd company logo
CSS POSITIONING
& FLOATING
Advanced CSS techniques
how to position
1. Determine the method of positioning
      position:static;
      position:relative;
      position:absolute;
      position:fixed;

2. Specify the actual numerical values for
   its exact coordinates
      left:100px;    right:200px;
      top:50px;      bottom:5px;
POSITION: STATIC
• Default setting
• Positions itself according to the “normal
  flow” (order of declaration of elements
  in the HTML, etc)
• rules like left:10px;   top:30%; do not
  work
POSITION: RELATIVE
• Positions itself according to its default
    position
• Still follows the “normal flow”, maintains
    its previous space occupied
•   position:relative;
    top:50px; left:50px;
    box moves 50px down (away from the top
    edge), and 50px to the right (away from
    the left edge) from its previous position
position: absolute
• Element is removed/lifted from the
    container element, and positioned
    according to the edges of the canvas
•   position:absolute;
    top:0px; left:0px;
    box is attached to the upper-left corner of
    the canvas, not the container element
position: fixed
• Positioned according to the browser
• Remains fixed, does not scroll with the
    content
•   position:fixed;
    left:0; top:0;
    box attaches to the top-left corner, and
    does not move with the content when
    scrolled
floating

• Floating makes objects line up in one
  side of its container element, and
  allowing other elements to flow around
  it
• First used to wrap text around images
More on Floating

• Objects will only float as far as its
  container element
• When floating block-elements, always
  define a width
floating boxes
• Fix dimensions
 .sample {            .samplethree {
 background:yellow;   background:orange;
 width:400px;         width:400px;
 height:100px;        height:80px;
 }                    }
 .sampletwo {
 background:pink;
 width:400px;
 height:60px;
 }
Floating with text
• Add float property to the last box
  .samplethree {
  background-color:orange;
  width:400px;
  height:80px;
  float:left;
  }
floating boxes
•   Add float property   .sampletwo {
                         background:pink;
    also to the first
                         width:400px;
    two                  height:100px;
                         float:left
    .sample {            }
    background:yellow;
    width:400px;
    height:100px;
    float:left;
    }
Float Direction
•   Change all to        width:400px;
                         height:60px;
    float:right
                         float:right
    .sample {
                         }
    background:yellow;
                         .samplethree {
    width:400px;
                         background:orange;
    height:100px;
                         width:400px;
    float:right;
                         height:80px;
    }
                         float:right
    .sampletwo {
                         }
    background:pink;
Clear property
• Clearing an object will turn-off the
  floating, thus it will appear below an
  element that is floated in that direction
  clear:left;
  clear:right;
  clear:both;
Clear in action
•   Float only the first   width:400px;
                           height:60px;
    box
    .sample {              float:right;
    background:yellow;     }
    width:400px;           .samplethree {
    height:100px;          background:orange;
    float:right;           width:400px;
    }                      height:80px;
    .sampletwo {           float:right;
    background:pink;       }
Clear in action
•   Add clear to the     width:400px;
                         height:60px;
    pink box
    .sample {            clear:right;
    background:yellow;   }
    width:400px;         .samplethree {
    height:100px;        background:orange;
    float:right;         width:400px;
    }                    height:80px;
    .sampletwo {         }
    background:pink;

More Related Content

What's hot

Chapter 15: Floating and Positioning
Chapter 15: Floating and Positioning Chapter 15: Floating and Positioning
Chapter 15: Floating and Positioning
Steve Guinan
 
Elements of html powerpoint
Elements of html powerpointElements of html powerpoint
Elements of html powerpoint
Anastasia1993
 
CSS Animations & Transitions
CSS Animations & TransitionsCSS Animations & Transitions
CSS Animations & Transitions
Edward Meehan
 
CSS
CSSCSS
CSS Selectors
CSS SelectorsCSS Selectors
CSS Selectors
Rachel Andrew
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
Walid Ashraf
 
java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technology
Tanmoy Barman
 
Css floats
Css floatsCss floats
Css floats
Webtech Learning
 
Introducing CSS Grid
Introducing CSS GridIntroducing CSS Grid
Introducing CSS Grid
Jason Yingling
 
Css animation
Css animationCss animation
Css animation
Aaron King
 
Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)
Chris Poteet
 
CSS Position and it’s values
CSS Position and it’s valuesCSS Position and it’s values
CSS Position and it’s values
Gunjan Tulsiani
 
HTML and CSS crash course!
HTML and CSS crash course!HTML and CSS crash course!
HTML and CSS crash course!
Ana Cidre
 
Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
DHTMLExtreme
 
Intro to Flexbox - A Magical CSS Property
Intro to Flexbox - A Magical CSS PropertyIntro to Flexbox - A Magical CSS Property
Intro to Flexbox - A Magical CSS Property
Adam Soucie
 
CSS Layouting #2 : Dimensi & Overflow
CSS Layouting #2 : Dimensi & OverflowCSS Layouting #2 : Dimensi & Overflow
CSS Layouting #2 : Dimensi & Overflow
Sandhika Galih
 

What's hot (20)

Chapter 15: Floating and Positioning
Chapter 15: Floating and Positioning Chapter 15: Floating and Positioning
Chapter 15: Floating and Positioning
 
Wrapper classes
Wrapper classesWrapper classes
Wrapper classes
 
Elements of html powerpoint
Elements of html powerpointElements of html powerpoint
Elements of html powerpoint
 
CSS Animations & Transitions
CSS Animations & TransitionsCSS Animations & Transitions
CSS Animations & Transitions
 
CSS
CSSCSS
CSS
 
Introducing Cascading Style Sheets
Introducing Cascading Style SheetsIntroducing Cascading Style Sheets
Introducing Cascading Style Sheets
 
CSS Selectors
CSS SelectorsCSS Selectors
CSS Selectors
 
Css Ppt
Css PptCss Ppt
Css Ppt
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
 
java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technology
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Css floats
Css floatsCss floats
Css floats
 
Introducing CSS Grid
Introducing CSS GridIntroducing CSS Grid
Introducing CSS Grid
 
Css animation
Css animationCss animation
Css animation
 
Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)
 
CSS Position and it’s values
CSS Position and it’s valuesCSS Position and it’s values
CSS Position and it’s values
 
HTML and CSS crash course!
HTML and CSS crash course!HTML and CSS crash course!
HTML and CSS crash course!
 
Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
 
Intro to Flexbox - A Magical CSS Property
Intro to Flexbox - A Magical CSS PropertyIntro to Flexbox - A Magical CSS Property
Intro to Flexbox - A Magical CSS Property
 
CSS Layouting #2 : Dimensi & Overflow
CSS Layouting #2 : Dimensi & OverflowCSS Layouting #2 : Dimensi & Overflow
CSS Layouting #2 : Dimensi & Overflow
 

Viewers also liked

Css Positioning Elements
Css Positioning ElementsCss Positioning Elements
Css Positioning Elementssanjay2211
 
CSS Positioning
CSS PositioningCSS Positioning
Shaping Up With CSS
Shaping Up With CSSShaping Up With CSS
Shaping Up With CSSsdireland
 
HTML&CSS 6 - Advanced CSS
HTML&CSS 6 - Advanced CSSHTML&CSS 6 - Advanced CSS
HTML&CSS 6 - Advanced CSS
Dinis Correia
 
CSS Layouting #5 : Position
CSS Layouting #5 : PositionCSS Layouting #5 : Position
CSS Layouting #5 : Position
Sandhika Galih
 
CSS Layout
CSS LayoutCSS Layout
CSS Layout
景智 張
 
1 07-2-css floats-and_positioning
1 07-2-css floats-and_positioning1 07-2-css floats-and_positioning
1 07-2-css floats-and_positioningapnwebdev
 
Lesson 108 23 aug13-1430-ay
Lesson 108 23 aug13-1430-ayLesson 108 23 aug13-1430-ay
Lesson 108 23 aug13-1430-ayCodecademy Ren
 
SVG - Scalable Vector Graphic
SVG - Scalable Vector GraphicSVG - Scalable Vector Graphic
SVG - Scalable Vector Graphic
Akila Iroshan
 
5 domain name worksheet
5   domain name worksheet5   domain name worksheet
5 domain name worksheet
viet nghiem
 
CSS font-stacks
CSS font-stacksCSS font-stacks
CSS font-stacks
Russ Weakley
 
Floating
FloatingFloating
Floating
Danielle Larson
 
The Box Model
The Box ModelThe Box Model
The Box Modelsdireland
 
Understanding the flex layout
Understanding the flex layoutUnderstanding the flex layout
Understanding the flex layout
Barak Drechsler
 
Intro to OOCSS Workshop
Intro to OOCSS WorkshopIntro to OOCSS Workshop
Intro to OOCSS Workshop
Julie Cameron
 
Anatomy Of A Domain Name and URL
Anatomy Of A Domain Name and URLAnatomy Of A Domain Name and URL
Anatomy Of A Domain Name and URL
Andy Wibbels
 
CSS3 filterとtransformをtransition, animationでアニメーション
CSS3 filterとtransformをtransition, animationでアニメーションCSS3 filterとtransformをtransition, animationでアニメーション
CSS3 filterとtransformをtransition, animationでアニメーション
Hiroaki Okubo
 
Cascading Style Sheets - Part 02
Cascading Style Sheets - Part 02Cascading Style Sheets - Part 02
Cascading Style Sheets - Part 02
Hatem Mahmoud
 
Purchase Your Domain Name
Purchase Your Domain NamePurchase Your Domain Name
Purchase Your Domain Name
Courtney Engle
 

Viewers also liked (20)

Css Positioning Elements
Css Positioning ElementsCss Positioning Elements
Css Positioning Elements
 
CSS Positioning
CSS PositioningCSS Positioning
CSS Positioning
 
Shaping Up With CSS
Shaping Up With CSSShaping Up With CSS
Shaping Up With CSS
 
HTML&CSS 6 - Advanced CSS
HTML&CSS 6 - Advanced CSSHTML&CSS 6 - Advanced CSS
HTML&CSS 6 - Advanced CSS
 
CSS Layouting #5 : Position
CSS Layouting #5 : PositionCSS Layouting #5 : Position
CSS Layouting #5 : Position
 
CSS Layout
CSS LayoutCSS Layout
CSS Layout
 
1 07-2-css floats-and_positioning
1 07-2-css floats-and_positioning1 07-2-css floats-and_positioning
1 07-2-css floats-and_positioning
 
Lesson 108 23 aug13-1430-ay
Lesson 108 23 aug13-1430-ayLesson 108 23 aug13-1430-ay
Lesson 108 23 aug13-1430-ay
 
SVG - Scalable Vector Graphic
SVG - Scalable Vector GraphicSVG - Scalable Vector Graphic
SVG - Scalable Vector Graphic
 
Layout
LayoutLayout
Layout
 
5 domain name worksheet
5   domain name worksheet5   domain name worksheet
5 domain name worksheet
 
CSS font-stacks
CSS font-stacksCSS font-stacks
CSS font-stacks
 
Floating
FloatingFloating
Floating
 
The Box Model
The Box ModelThe Box Model
The Box Model
 
Understanding the flex layout
Understanding the flex layoutUnderstanding the flex layout
Understanding the flex layout
 
Intro to OOCSS Workshop
Intro to OOCSS WorkshopIntro to OOCSS Workshop
Intro to OOCSS Workshop
 
Anatomy Of A Domain Name and URL
Anatomy Of A Domain Name and URLAnatomy Of A Domain Name and URL
Anatomy Of A Domain Name and URL
 
CSS3 filterとtransformをtransition, animationでアニメーション
CSS3 filterとtransformをtransition, animationでアニメーションCSS3 filterとtransformをtransition, animationでアニメーション
CSS3 filterとtransformをtransition, animationでアニメーション
 
Cascading Style Sheets - Part 02
Cascading Style Sheets - Part 02Cascading Style Sheets - Part 02
Cascading Style Sheets - Part 02
 
Purchase Your Domain Name
Purchase Your Domain NamePurchase Your Domain Name
Purchase Your Domain Name
 

More from Gerson Abesamis

YMSAT Project Proposal Form
YMSAT Project Proposal FormYMSAT Project Proposal Form
YMSAT Project Proposal Form
Gerson Abesamis
 
YMSAT Student Primer
YMSAT Student PrimerYMSAT Student Primer
YMSAT Student Primer
Gerson Abesamis
 
960 Grid System
960 Grid System960 Grid System
960 Grid System
Gerson Abesamis
 
Photography Orientation 11-12
Photography Orientation 11-12Photography Orientation 11-12
Photography Orientation 11-12Gerson Abesamis
 
WebDev2 Orientation 11-12
WebDev2 Orientation 11-12WebDev2 Orientation 11-12
WebDev2 Orientation 11-12Gerson Abesamis
 
Pinhole photography vale
Pinhole photography valePinhole photography vale
Pinhole photography valeGerson Abesamis
 
CSS Box Model and Dimensions
CSS Box Model and DimensionsCSS Box Model and Dimensions
CSS Box Model and DimensionsGerson Abesamis
 
Information Architecture
Information ArchitectureInformation Architecture
Information ArchitectureGerson Abesamis
 

More from Gerson Abesamis (20)

YMSAT Project Proposal Form
YMSAT Project Proposal FormYMSAT Project Proposal Form
YMSAT Project Proposal Form
 
YMSAT Student Primer
YMSAT Student PrimerYMSAT Student Primer
YMSAT Student Primer
 
Final Project
Final ProjectFinal Project
Final Project
 
960 Grid System
960 Grid System960 Grid System
960 Grid System
 
CSS Box Model
CSS Box ModelCSS Box Model
CSS Box Model
 
Photography Orientation 11-12
Photography Orientation 11-12Photography Orientation 11-12
Photography Orientation 11-12
 
WebDev2 Orientation 11-12
WebDev2 Orientation 11-12WebDev2 Orientation 11-12
WebDev2 Orientation 11-12
 
Photography Class 11-12
Photography Class 11-12Photography Class 11-12
Photography Class 11-12
 
Prewar report
Prewar reportPrewar report
Prewar report
 
Typo Graphics
Typo GraphicsTypo Graphics
Typo Graphics
 
Web Typography
Web TypographyWeb Typography
Web Typography
 
Typographic Contrast
Typographic ContrastTypographic Contrast
Typographic Contrast
 
WebDev Template Finals
WebDev Template FinalsWebDev Template Finals
WebDev Template Finals
 
Pinhole photography vale
Pinhole photography valePinhole photography vale
Pinhole photography vale
 
CSS Box Model and Dimensions
CSS Box Model and DimensionsCSS Box Model and Dimensions
CSS Box Model and Dimensions
 
Interface Design
Interface DesignInterface Design
Interface Design
 
CSS Lists and Tables
CSS Lists and TablesCSS Lists and Tables
CSS Lists and Tables
 
CSS Refresher
CSS RefresherCSS Refresher
CSS Refresher
 
Intro to HTML
Intro to HTMLIntro to HTML
Intro to HTML
 
Information Architecture
Information ArchitectureInformation Architecture
Information Architecture
 

Css positioning

  • 2. how to position 1. Determine the method of positioning position:static; position:relative; position:absolute; position:fixed; 2. Specify the actual numerical values for its exact coordinates left:100px; right:200px; top:50px; bottom:5px;
  • 3. POSITION: STATIC • Default setting • Positions itself according to the “normal flow” (order of declaration of elements in the HTML, etc) • rules like left:10px; top:30%; do not work
  • 4.
  • 5. POSITION: RELATIVE • Positions itself according to its default position • Still follows the “normal flow”, maintains its previous space occupied • position:relative; top:50px; left:50px; box moves 50px down (away from the top edge), and 50px to the right (away from the left edge) from its previous position
  • 6.
  • 7. position: absolute • Element is removed/lifted from the container element, and positioned according to the edges of the canvas • position:absolute; top:0px; left:0px; box is attached to the upper-left corner of the canvas, not the container element
  • 8.
  • 9. position: fixed • Positioned according to the browser • Remains fixed, does not scroll with the content • position:fixed; left:0; top:0; box attaches to the top-left corner, and does not move with the content when scrolled
  • 10.
  • 11.
  • 12. floating • Floating makes objects line up in one side of its container element, and allowing other elements to flow around it • First used to wrap text around images
  • 13.
  • 14. More on Floating • Objects will only float as far as its container element • When floating block-elements, always define a width
  • 15.
  • 16. floating boxes • Fix dimensions .sample { .samplethree { background:yellow; background:orange; width:400px; width:400px; height:100px; height:80px; } } .sampletwo { background:pink; width:400px; height:60px; }
  • 17.
  • 18. Floating with text • Add float property to the last box .samplethree { background-color:orange; width:400px; height:80px; float:left; }
  • 19.
  • 20. floating boxes • Add float property .sampletwo { background:pink; also to the first width:400px; two height:100px; float:left .sample { } background:yellow; width:400px; height:100px; float:left; }
  • 21.
  • 22. Float Direction • Change all to width:400px; height:60px; float:right float:right .sample { } background:yellow; .samplethree { width:400px; background:orange; height:100px; width:400px; float:right; height:80px; } float:right .sampletwo { } background:pink;
  • 23.
  • 24. Clear property • Clearing an object will turn-off the floating, thus it will appear below an element that is floated in that direction clear:left; clear:right; clear:both;
  • 25.
  • 26. Clear in action • Float only the first width:400px; height:60px; box .sample { float:right; background:yellow; } width:400px; .samplethree { height:100px; background:orange; float:right; width:400px; } height:80px; .sampletwo { float:right; background:pink; }
  • 27.
  • 28. Clear in action • Add clear to the width:400px; height:60px; pink box .sample { clear:right; background:yellow; } width:400px; .samplethree { height:100px; background:orange; float:right; width:400px; } height:80px; .sampletwo { } background:pink;