SlideShare a Scribd company logo
1 of 7
Nesting and Floating Elements
Nesting <div> elements: ,[object Object],[object Object],[object Object]
A nested <div> example: Here we have placed a container (pink) inside another container (blue), which itself is inside a parent container (yellow). <head> <style type=&quot;text/css&quot;> .yellow { width:400px; height:400px; background-color:yellow; } .blue { width:200px; height:200px; background-color:blue; } .pink { width:100px; height:100px; background-color:pink; } </style> </head> <div class=&quot;yellow&quot;> <div class=&quot;blue&quot;> <div class=&quot;pink&quot;></div> </div> <!-- blue --> </div> <!-- yellow --> Notice the comments added to the last two closing </div> tags. These can help us later, especially when there is a lot of code between the opening and closing tags.
Floating elements: ,[object Object],[object Object]
Floating <div> elements: When we float elements, subsequent content stays at the same horizontal level and uses whatever space remains.  Once that space is used up, the content will &quot;wrap&quot; to the beginning of the next line. <head> <style type=&quot;text/css&quot;> .first { width:100px; height:100px; background-color:blue; float:left; } .second { width:100px; height:100px; background-color:yellow; float:left; } </style> </head> <div class=&quot;first&quot;></div> <div class=&quot;second&quot;></div> More content.<br /> More content.<br /> More content.<br /> More content.<br /> More content.<br /> More content. More content. More content. More content. More content.
Floating right and left: We can also float elements to both the right and left sides of the page.  The subsequent content will still behave the same way, filling whatever space remains untaken by the floated elements. <head> <style type=&quot;text/css&quot;> .first { width:100px; height:100px; background-color:blue; float:left; } .second { width:100px; height:100px; background-color:yellow; float:right; } </style> </head> <div class=&quot;first&quot;></div> <div class=&quot;second&quot;></div> More content.<br /> More content.<br /> More content.<br /> More content.<br /> More content.<br /> More content. More content. More content. More content. More content. This is commonly done to create a web page with three columns.  A navigation bar will be floated left, an information bar floated right, and the main content will reside in the middle of the page.
Clearing the float: If we want to force the next element to start below the floated elements, we can clear the float. <head> <style type=&quot;text/css&quot;> .first { width:100px; height:100px; background-color:blue; float:left; } .second { width:100px; height:100px; background-color:yellow; float:right; } .clearfloat { clear:both; } </style> </head> <div class=&quot;first&quot;></div> <div class=&quot;second&quot;></div> <div class=&quot;clearfloat&quot;></div> More content.<br /> . . . More content. More content. More content. More content. More content.

More Related Content

What's hot

C S S Top Elements
C S S  Top  ElementsC S S  Top  Elements
C S S Top Elements
ehorner
 
Anvita Dynamic Fontson Web Feb2001
Anvita Dynamic Fontson Web Feb2001Anvita Dynamic Fontson Web Feb2001
Anvita Dynamic Fontson Web Feb2001
guest6e7a1b1
 
Basics tags for HTML
Basics tags for HTMLBasics tags for HTML
Basics tags for HTML
vidyamittal
 
La sociedad del conocimiento
La sociedad del conocimientoLa sociedad del conocimiento
La sociedad del conocimiento
vyalb
 

What's hot (20)

C S S Top Elements
C S S  Top  ElementsC S S  Top  Elements
C S S Top Elements
 
Block2 Session2 Presentation
Block2 Session2 PresentationBlock2 Session2 Presentation
Block2 Session2 Presentation
 
Learning HTML
Learning HTMLLearning HTML
Learning HTML
 
How an html file is structured
How an html file is structuredHow an html file is structured
How an html file is structured
 
Hour 02
Hour 02Hour 02
Hour 02
 
Html tutorial
Html tutorialHtml tutorial
Html tutorial
 
JWU Guest Talk: JavaScript and AJAX
JWU Guest Talk: JavaScript and AJAXJWU Guest Talk: JavaScript and AJAX
JWU Guest Talk: JavaScript and AJAX
 
Randy Witt Audio Assignment
Randy Witt Audio AssignmentRandy Witt Audio Assignment
Randy Witt Audio Assignment
 
Basic HTML
Basic HTMLBasic HTML
Basic HTML
 
Cheat codes
Cheat codesCheat codes
Cheat codes
 
How To Become A Web Page Master Builder
How To Become A Web Page Master BuilderHow To Become A Web Page Master Builder
How To Become A Web Page Master Builder
 
Anvita Dynamic Fontson Web Feb2001
Anvita Dynamic Fontson Web Feb2001Anvita Dynamic Fontson Web Feb2001
Anvita Dynamic Fontson Web Feb2001
 
Basics tags for HTML
Basics tags for HTMLBasics tags for HTML
Basics tags for HTML
 
New HTML5/CSS3 techniques
New HTML5/CSS3 techniquesNew HTML5/CSS3 techniques
New HTML5/CSS3 techniques
 
La sociedad del conocimiento
La sociedad del conocimientoLa sociedad del conocimiento
La sociedad del conocimiento
 
HTML presentation for beginners
HTML presentation for beginnersHTML presentation for beginners
HTML presentation for beginners
 
Html basics IML 140 (weeks 2-3)
Html basics IML 140 (weeks 2-3)Html basics IML 140 (weeks 2-3)
Html basics IML 140 (weeks 2-3)
 
Javascript
JavascriptJavascript
Javascript
 
The Basics of (X)HTML Tags
The Basics of (X)HTML TagsThe Basics of (X)HTML Tags
The Basics of (X)HTML Tags
 
Understanding html
Understanding htmlUnderstanding html
Understanding html
 

Viewers also liked (20)

Dövrlər
DövrlərDövrlər
Dövrlər
 
Chachies del boske nuboso
Chachies del boske nubosoChachies del boske nuboso
Chachies del boske nuboso
 
TPA-AL Wiki Explained
TPA-AL Wiki ExplainedTPA-AL Wiki Explained
TPA-AL Wiki Explained
 
Kade karu ott 2
Kade karu ott 2Kade karu ott 2
Kade karu ott 2
 
Erosion pdf
Erosion pdfErosion pdf
Erosion pdf
 
Eco world- Snežana
Eco world- SnežanaEco world- Snežana
Eco world- Snežana
 
Comenius Liiverpool
Comenius LiiverpoolComenius Liiverpool
Comenius Liiverpool
 
Ecologic footprint
Ecologic footprintEcologic footprint
Ecologic footprint
 
Jingle bells power point
Jingle bells power pointJingle bells power point
Jingle bells power point
 
1.4 adding comments copy (2)
1.4 adding comments   copy (2)1.4 adding comments   copy (2)
1.4 adding comments copy (2)
 
Špoģi-Syke
Špoģi-Syke  Špoģi-Syke
Špoģi-Syke
 
This is our school, zrenjaninska gimnazija (zrenjanin grammar school), serbia
This is our school, zrenjaninska gimnazija (zrenjanin grammar school), serbiaThis is our school, zrenjaninska gimnazija (zrenjanin grammar school), serbia
This is our school, zrenjaninska gimnazija (zrenjanin grammar school), serbia
 
Dress from newspapers_-_copy (1)
Dress from newspapers_-_copy (1)Dress from newspapers_-_copy (1)
Dress from newspapers_-_copy (1)
 
American Campaign to supress Islam
American Campaign to supress IslamAmerican Campaign to supress Islam
American Campaign to supress Islam
 
Millatfacebook
MillatfacebookMillatfacebook
Millatfacebook
 
The reed flute cave
The reed flute caveThe reed flute cave
The reed flute cave
 
1.3 creating links
1.3 creating links1.3 creating links
1.3 creating links
 
Idiom 1
Idiom  1Idiom  1
Idiom 1
 
Power e
Power ePower e
Power e
 
Questionnaire results students-teachers-zr
Questionnaire results students-teachers-zrQuestionnaire results students-teachers-zr
Questionnaire results students-teachers-zr
 

Similar to 5.2 nesting and floating elements

Introduction to html
Introduction to htmlIntroduction to html
Introduction to html
vikasgaur31
 
Introduction to html
Introduction to htmlIntroduction to html
Introduction to html
vikasgaur31
 
1.2 elements and attributes copy (3)
1.2 elements and attributes   copy (3)1.2 elements and attributes   copy (3)
1.2 elements and attributes copy (3)
Bulldogs83
 
1.2 elements and attributes copy (3)
1.2 elements and attributes   copy (3)1.2 elements and attributes   copy (3)
1.2 elements and attributes copy (3)
Bulldogs83
 
Webpages And Dynamic Content
Webpages And Dynamic ContentWebpages And Dynamic Content
Webpages And Dynamic Content
maycourse
 
Lecture 1 - Comm Lab: Web @ ITP
Lecture 1 - Comm Lab: Web @ ITPLecture 1 - Comm Lab: Web @ ITP
Lecture 1 - Comm Lab: Web @ ITP
yucefmerhi
 
Kml Basics Chpt 2 Placemarks
Kml Basics Chpt  2   PlacemarksKml Basics Chpt  2   Placemarks
Kml Basics Chpt 2 Placemarks
tcooper66
 

Similar to 5.2 nesting and floating elements (20)

Haml, Sass & Compass
Haml, Sass & CompassHaml, Sass & Compass
Haml, Sass & Compass
 
How To Create Personal Web Pages On My Web
How To Create Personal Web Pages On My WebHow To Create Personal Web Pages On My Web
How To Create Personal Web Pages On My Web
 
Front End on Rails
Front End on RailsFront End on Rails
Front End on Rails
 
KMUTNB - Internet Programming 3/7
KMUTNB - Internet Programming 3/7KMUTNB - Internet Programming 3/7
KMUTNB - Internet Programming 3/7
 
Introduction to html
Introduction to htmlIntroduction to html
Introduction to html
 
Introduction to html
Introduction to htmlIntroduction to html
Introduction to html
 
1.2 elements and attributes copy (3)
1.2 elements and attributes   copy (3)1.2 elements and attributes   copy (3)
1.2 elements and attributes copy (3)
 
1.2 elements and attributes copy (3)
1.2 elements and attributes   copy (3)1.2 elements and attributes   copy (3)
1.2 elements and attributes copy (3)
 
The Frameless Opac
The Frameless OpacThe Frameless Opac
The Frameless Opac
 
Lecture 2 - Comm Lab: Web @ ITP
Lecture 2 - Comm Lab: Web @ ITPLecture 2 - Comm Lab: Web @ ITP
Lecture 2 - Comm Lab: Web @ ITP
 
Webpages And Dynamic Content
Webpages And Dynamic ContentWebpages And Dynamic Content
Webpages And Dynamic Content
 
CSS
CSSCSS
CSS
 
Web Designing
Web DesigningWeb Designing
Web Designing
 
Lecture 1 - Comm Lab: Web @ ITP
Lecture 1 - Comm Lab: Web @ ITPLecture 1 - Comm Lab: Web @ ITP
Lecture 1 - Comm Lab: Web @ ITP
 
Kml Basics Chpt 2 Placemarks
Kml Basics Chpt  2   PlacemarksKml Basics Chpt  2   Placemarks
Kml Basics Chpt 2 Placemarks
 
CSS
CSSCSS
CSS
 
Diva
DivaDiva
Diva
 
Tor2
Tor2Tor2
Tor2
 
Css advanced – session 5
Css advanced – session 5Css advanced – session 5
Css advanced – session 5
 
HTML & CSS
HTML & CSSHTML & CSS
HTML & CSS
 

More from Bulldogs83

7.2 external style sheets
7.2 external style sheets7.2 external style sheets
7.2 external style sheets
Bulldogs83
 
7.1 xhtml validation
7.1 xhtml validation7.1 xhtml validation
7.1 xhtml validation
Bulldogs83
 
6.2 css link styling
6.2 css link styling6.2 css link styling
6.2 css link styling
Bulldogs83
 
6.1 special characters
6.1 special characters6.1 special characters
6.1 special characters
Bulldogs83
 
5.1 css box model
5.1 css box model5.1 css box model
5.1 css box model
Bulldogs83
 
4.3 table styling
4.3 table styling4.3 table styling
4.3 table styling
Bulldogs83
 
4.2 css classes
4.2 css classes4.2 css classes
4.2 css classes
Bulldogs83
 
4.1 advanced tables
4.1 advanced tables4.1 advanced tables
4.1 advanced tables
Bulldogs83
 
3.2 introduction to css
3.2 introduction to css3.2 introduction to css
3.2 introduction to css
Bulldogs83
 
3.1 xhtml tables
3.1 xhtml tables3.1 xhtml tables
3.1 xhtml tables
Bulldogs83
 
3.2 introduction to css
3.2 introduction to css3.2 introduction to css
3.2 introduction to css
Bulldogs83
 
2.1 adding images
2.1 adding images2.1 adding images
2.1 adding images
Bulldogs83
 
1.4 adding comments copy (2)
1.4 adding comments   copy (2)1.4 adding comments   copy (2)
1.4 adding comments copy (2)
Bulldogs83
 
1.3 creating links
1.3 creating links1.3 creating links
1.3 creating links
Bulldogs83
 

More from Bulldogs83 (14)

7.2 external style sheets
7.2 external style sheets7.2 external style sheets
7.2 external style sheets
 
7.1 xhtml validation
7.1 xhtml validation7.1 xhtml validation
7.1 xhtml validation
 
6.2 css link styling
6.2 css link styling6.2 css link styling
6.2 css link styling
 
6.1 special characters
6.1 special characters6.1 special characters
6.1 special characters
 
5.1 css box model
5.1 css box model5.1 css box model
5.1 css box model
 
4.3 table styling
4.3 table styling4.3 table styling
4.3 table styling
 
4.2 css classes
4.2 css classes4.2 css classes
4.2 css classes
 
4.1 advanced tables
4.1 advanced tables4.1 advanced tables
4.1 advanced tables
 
3.2 introduction to css
3.2 introduction to css3.2 introduction to css
3.2 introduction to css
 
3.1 xhtml tables
3.1 xhtml tables3.1 xhtml tables
3.1 xhtml tables
 
3.2 introduction to css
3.2 introduction to css3.2 introduction to css
3.2 introduction to css
 
2.1 adding images
2.1 adding images2.1 adding images
2.1 adding images
 
1.4 adding comments copy (2)
1.4 adding comments   copy (2)1.4 adding comments   copy (2)
1.4 adding comments copy (2)
 
1.3 creating links
1.3 creating links1.3 creating links
1.3 creating links
 

Recently uploaded

Recently uploaded (20)

SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 

5.2 nesting and floating elements

  • 2.
  • 3. A nested <div> example: Here we have placed a container (pink) inside another container (blue), which itself is inside a parent container (yellow). <head> <style type=&quot;text/css&quot;> .yellow { width:400px; height:400px; background-color:yellow; } .blue { width:200px; height:200px; background-color:blue; } .pink { width:100px; height:100px; background-color:pink; } </style> </head> <div class=&quot;yellow&quot;> <div class=&quot;blue&quot;> <div class=&quot;pink&quot;></div> </div> <!-- blue --> </div> <!-- yellow --> Notice the comments added to the last two closing </div> tags. These can help us later, especially when there is a lot of code between the opening and closing tags.
  • 4.
  • 5. Floating <div> elements: When we float elements, subsequent content stays at the same horizontal level and uses whatever space remains. Once that space is used up, the content will &quot;wrap&quot; to the beginning of the next line. <head> <style type=&quot;text/css&quot;> .first { width:100px; height:100px; background-color:blue; float:left; } .second { width:100px; height:100px; background-color:yellow; float:left; } </style> </head> <div class=&quot;first&quot;></div> <div class=&quot;second&quot;></div> More content.<br /> More content.<br /> More content.<br /> More content.<br /> More content.<br /> More content. More content. More content. More content. More content.
  • 6. Floating right and left: We can also float elements to both the right and left sides of the page. The subsequent content will still behave the same way, filling whatever space remains untaken by the floated elements. <head> <style type=&quot;text/css&quot;> .first { width:100px; height:100px; background-color:blue; float:left; } .second { width:100px; height:100px; background-color:yellow; float:right; } </style> </head> <div class=&quot;first&quot;></div> <div class=&quot;second&quot;></div> More content.<br /> More content.<br /> More content.<br /> More content.<br /> More content.<br /> More content. More content. More content. More content. More content. This is commonly done to create a web page with three columns. A navigation bar will be floated left, an information bar floated right, and the main content will reside in the middle of the page.
  • 7. Clearing the float: If we want to force the next element to start below the floated elements, we can clear the float. <head> <style type=&quot;text/css&quot;> .first { width:100px; height:100px; background-color:blue; float:left; } .second { width:100px; height:100px; background-color:yellow; float:right; } .clearfloat { clear:both; } </style> </head> <div class=&quot;first&quot;></div> <div class=&quot;second&quot;></div> <div class=&quot;clearfloat&quot;></div> More content.<br /> . . . More content. More content. More content. More content. More content.