SlideShare a Scribd company logo
The fundamentals
of browser
rendering - part 2
By Barak Drechsler
Fundamentals of Browser Rendering Css Overview PT 2
Recap from our previous
session...
1. We discussed the browser rendering flow DOM + CSSOM => Render Tree => Layout =>
paint.
2. Each element is box.
3. It size is defined by it box-model, either (content-box or border-box).
4. We have a different types of boxes which affect element behaviour (inline, block, inline-
block, flex, none)
Today's Agenda
We now have to see, how can we define how elements are aligned together.
Floats
Positioning
Collapsing Margins
Z-index and elements visibility order (stacking context).
Float
The float CSS property specifies that an element should be taken from the normal flow and
placed along the left or right side of its container, where text and inline elements will wrap
around it.
A floating element is one where the computed value of float is not none.
(MDN)
Play Time - floats
https://plnkr.co/edit/Bz4hS2E9e
mkbr3fvts16?p=preview
Floats Tricky Parts
Float - summary
1. When an element is floated it is taken out of the normal flow of the document. It is shifted
to the left or right until it touches the edge of its containing box or another floated element.
2. Float elements must be given explicit width, otherwise unexpected behavior could occur.
3. Non-positioned, non-floated, block-level elements act as if the floated element is not there.
4. To make parent of floats take it height, we must clear the floats, a trick could be adding
overflow: auto.
5. Bootstrap grid system is float based.
Positioning
1. Positioning allows you to move an element around the document.
2. We have 4 types of Positioning:
a. Static (default)
b. Relative
c. Absolute
d. Fixed
Static
The default value for all elements, represents the normal document flow.
Position related attributes have no effect (top, left, etc…)
Only usage is to override and reset other position values.
Isn’t affected by z-index.
Relative
This keyword lays out all elements as though the element were not positioned, and then adjust
the element's position, without changing layout (and thus leaving a gap for the element where it
would have been had it not been positioned (MDN)
- The Element starts where it should have been
- You can move it from it’s original position via (top, left, etc…)
- limits the scope of absolutely positioned child elements
Absolute
Do not leave space for the element. Instead, position it at a specified position relative to its
closest positioned ancestor if any, or otherwise relative to the initial containing block.
Absolutely positioned boxes can have margins, and they do not collapse with any other
margins. (MDN)
- The element is out of the browser flow, meaning it won’t be affected by other elements.
- Also it won’t affect other elements flow.
- Will be relative to it closest non static parent, or to the html tag itself if none found.
Fixed
Do not leave space for the element.
Instead, position it at a specified position relative to the screen's viewport and don't move it
when scrolled. When printing, position it at that fixed position on every page. This value always
create a new stacking context (MDN).
Play Time - Positions
https://plnkr.co/edit/JosJySkjT7V
Ah4xuTp98?p=preview
Collapsing Margins
CSS, the adjoining margins of two or more boxes (which might or might not be siblings) can
combine to form a single margin. Margins that combine this way are said to collapse, and the
resulting combined margin is called a collapsed margin. (W3C SPEC)
In short: when two topbottom margins touch each other they collapse
1. The higher margin is taken, and the smaller collapse to 0.
2. Negative and positive margins are added up rather than collapse.
3. Two Negative margins collapse, with the smaller one taken.
Play Time - Collapsing Margins
https://plnkr.co/edit/wvaBa6A7R
9snWJVxoIOP?p=preview
Stacking context is the three-dimensional conceptualization of HTML elements along an
imaginary z-axis relative to the user who is assumed to be facing the viewport or the webpage.
HTML elements occupy this space in priority order based on element attributes. (MDN)
Elements Order without z-index, are formed by the HTML hierarchy:
1. Last elements in HTML order will be displayed on top.
2. Positioned Elements have higher priority over static elements, which is strong then html
order.
3rd Dimension, stacking context
Play Time - Stacking Context no
z-index.
https://plnkr.co/edit/9ygOvS1BiB
qsyatxcCML?p=preview
Positioning and assigning a z-index value to an HTML element creates a stacking context, (as
does assigning non-full opacity).
Stacking contexts can be contained in other stacking contexts, and together create a hierarchy
of stacking contexts.
Each stacking context is completely independent from its siblings: only descendant elements are
considered when stacking is processed.
Each stacking context is self-contained: after the element's contents are stacked, the whole
element is considered in the stacking order of the parent stacking context.
Z-index & multi hierarchy stacks
Play Time - Stacking Contexts
https://plnkr.co/edit/tzW4NsFWA
Hu0TLjAWEO1?p=preview
MDN menu example
Stacking Context - Summary
1. Stacking Context, is the concept of how the browser renders elements in the 3rd dimension
(facing browser window).
2. By default context order is derived from html order (last element on top)
3. Default order gives priority for positioned elements over static elements.
4. Each context can host more contexts, each stacking context is self-contained.
5. New contexts are created by certain conditions
a. HTML root
Other Worth Knowing...
1. Css Transform
2. Css Pseudo Elements, check this
3. MDN, anytime you are not sure about
what's going on...
Questions?

More Related Content

Similar to Fundamentals of Browser Rendering Css Overview PT 2 (20)

PPTX
Chapter 15: Floating and Positioning
Steve Guinan
 
PPTX
Designing for the web - 101
Ashraf Hamdy
 
PPTX
Chapter05-Presentation.pptx
ssuserf3db48
 
PPTX
Castro Chapter 11
Jeff Byrnes
 
PDF
CSS3 Refresher
Ivano Malavolta
 
PPTX
Css layout
club23
 
PDF
CSS - OOCSS, SMACSS and more
Russ Weakley
 
PPT
CSS Layout
Doncho Minkov
 
PPT
Css Positioning Elements
sanjay2211
 
PPTX
Lecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
ZahouAmel1
 
PDF
CSS3 Layout
Zoe Gillenwater
 
PPT
Laying Out Elements with CSS
Nicole Ryan
 
PPTX
CSS_Day_Three (W3schools)
Rafi Haidari
 
PPT
Css advanced – session 4
Dr. Ramkumar Lakshminarayanan
 
PPT
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
Deepak Sharma
 
PPT
Css best practices style guide and tips
Chris Love
 
PDF
Web Layout
Shawn Calvert
 
PDF
The Future of CSS Layout
Zoe Gillenwater
 
PPTX
Css intro
Julia Vi
 
PDF
CSS 201
Jennifer Berk
 
Chapter 15: Floating and Positioning
Steve Guinan
 
Designing for the web - 101
Ashraf Hamdy
 
Chapter05-Presentation.pptx
ssuserf3db48
 
Castro Chapter 11
Jeff Byrnes
 
CSS3 Refresher
Ivano Malavolta
 
Css layout
club23
 
CSS - OOCSS, SMACSS and more
Russ Weakley
 
CSS Layout
Doncho Minkov
 
Css Positioning Elements
sanjay2211
 
Lecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
ZahouAmel1
 
CSS3 Layout
Zoe Gillenwater
 
Laying Out Elements with CSS
Nicole Ryan
 
CSS_Day_Three (W3schools)
Rafi Haidari
 
Css advanced – session 4
Dr. Ramkumar Lakshminarayanan
 
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
Deepak Sharma
 
Css best practices style guide and tips
Chris Love
 
Web Layout
Shawn Calvert
 
The Future of CSS Layout
Zoe Gillenwater
 
Css intro
Julia Vi
 
CSS 201
Jennifer Berk
 

More from Barak Drechsler (6)

PPTX
Stay lazy, use lerna
Barak Drechsler
 
PPTX
Atomic javascript
Barak Drechsler
 
PPTX
Room service (worker) please!
Barak Drechsler
 
PPTX
From MVC to Component Based Architecture
Barak Drechsler
 
PPTX
Js: master prototypes
Barak Drechsler
 
PPTX
Understanding the flex layout
Barak Drechsler
 
Stay lazy, use lerna
Barak Drechsler
 
Atomic javascript
Barak Drechsler
 
Room service (worker) please!
Barak Drechsler
 
From MVC to Component Based Architecture
Barak Drechsler
 
Js: master prototypes
Barak Drechsler
 
Understanding the flex layout
Barak Drechsler
 
Ad

Recently uploaded (20)

PPT
Agilent Optoelectronic Solutions for Mobile Application
andreashenniger2
 
PPTX
internet básico presentacion es una red global
70965857
 
PPT
Computer Securityyyyyyyy - Chapter 1.ppt
SolomonSB
 
PPTX
ZARA-Case.pptx djdkkdjnddkdoodkdxjidjdnhdjjdjx
RonnelPineda2
 
PDF
Slides PDF format Eco Economic Epochs.pdf
Steven McGee
 
PPTX
英国学位证(RCM毕业证书)皇家音乐学院毕业证书如何办理
Taqyea
 
PPTX
sajflsajfljsdfljslfjslfsdfas;fdsfksadfjlsdflkjslgfs;lfjlsajfl;sajfasfd.pptx
theknightme
 
PPTX
ONLINE BIRTH CERTIFICATE APPLICATION SYSYTEM PPT.pptx
ShyamasreeDutta
 
PDF
𝐁𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓
hokimamad0
 
PDF
Web Hosting for Shopify WooCommerce etc.
Harry_Phoneix Harry_Phoneix
 
PPTX
本科硕士学历佛罗里达大学毕业证(UF毕业证书)24小时在线办理
Taqyea
 
PPTX
unit 2_2 copy right fdrgfdgfai and sm.pptx
nepmithibai2024
 
PPTX
Template Timeplan & Roadmap Product.pptx
ImeldaYulistya
 
PDF
Azure_DevOps introduction for CI/CD and Agile
henrymails
 
PDF
How to Fix Error Code 16 in Adobe Photoshop A Step-by-Step Guide.pdf
Becky Lean
 
PPTX
PE introd.pptxfrgfgfdgfdgfgrtretrt44t444
nepmithibai2024
 
PPT
Computer Securityyyyyyyy - Chapter 2.ppt
SolomonSB
 
PDF
𝐁𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓
hokimamad0
 
PPTX
一比一原版(LaTech毕业证)路易斯安那理工大学毕业证如何办理
Taqyea
 
PPTX
L1A Season 1 Guide made by A hegy Eng Grammar fixed
toszolder91
 
Agilent Optoelectronic Solutions for Mobile Application
andreashenniger2
 
internet básico presentacion es una red global
70965857
 
Computer Securityyyyyyyy - Chapter 1.ppt
SolomonSB
 
ZARA-Case.pptx djdkkdjnddkdoodkdxjidjdnhdjjdjx
RonnelPineda2
 
Slides PDF format Eco Economic Epochs.pdf
Steven McGee
 
英国学位证(RCM毕业证书)皇家音乐学院毕业证书如何办理
Taqyea
 
sajflsajfljsdfljslfjslfsdfas;fdsfksadfjlsdflkjslgfs;lfjlsajfl;sajfasfd.pptx
theknightme
 
ONLINE BIRTH CERTIFICATE APPLICATION SYSYTEM PPT.pptx
ShyamasreeDutta
 
𝐁𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓
hokimamad0
 
Web Hosting for Shopify WooCommerce etc.
Harry_Phoneix Harry_Phoneix
 
本科硕士学历佛罗里达大学毕业证(UF毕业证书)24小时在线办理
Taqyea
 
unit 2_2 copy right fdrgfdgfai and sm.pptx
nepmithibai2024
 
Template Timeplan & Roadmap Product.pptx
ImeldaYulistya
 
Azure_DevOps introduction for CI/CD and Agile
henrymails
 
How to Fix Error Code 16 in Adobe Photoshop A Step-by-Step Guide.pdf
Becky Lean
 
PE introd.pptxfrgfgfdgfdgfgrtretrt44t444
nepmithibai2024
 
Computer Securityyyyyyyy - Chapter 2.ppt
SolomonSB
 
𝐁𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓
hokimamad0
 
一比一原版(LaTech毕业证)路易斯安那理工大学毕业证如何办理
Taqyea
 
L1A Season 1 Guide made by A hegy Eng Grammar fixed
toszolder91
 
Ad

Fundamentals of Browser Rendering Css Overview PT 2

  • 1. The fundamentals of browser rendering - part 2 By Barak Drechsler
  • 3. Recap from our previous session... 1. We discussed the browser rendering flow DOM + CSSOM => Render Tree => Layout => paint. 2. Each element is box. 3. It size is defined by it box-model, either (content-box or border-box). 4. We have a different types of boxes which affect element behaviour (inline, block, inline- block, flex, none)
  • 4. Today's Agenda We now have to see, how can we define how elements are aligned together. Floats Positioning Collapsing Margins Z-index and elements visibility order (stacking context).
  • 5. Float The float CSS property specifies that an element should be taken from the normal flow and placed along the left or right side of its container, where text and inline elements will wrap around it. A floating element is one where the computed value of float is not none. (MDN)
  • 6. Play Time - floats https://plnkr.co/edit/Bz4hS2E9e mkbr3fvts16?p=preview Floats Tricky Parts
  • 7. Float - summary 1. When an element is floated it is taken out of the normal flow of the document. It is shifted to the left or right until it touches the edge of its containing box or another floated element. 2. Float elements must be given explicit width, otherwise unexpected behavior could occur. 3. Non-positioned, non-floated, block-level elements act as if the floated element is not there. 4. To make parent of floats take it height, we must clear the floats, a trick could be adding overflow: auto. 5. Bootstrap grid system is float based.
  • 8. Positioning 1. Positioning allows you to move an element around the document. 2. We have 4 types of Positioning: a. Static (default) b. Relative c. Absolute d. Fixed
  • 9. Static The default value for all elements, represents the normal document flow. Position related attributes have no effect (top, left, etc…) Only usage is to override and reset other position values. Isn’t affected by z-index.
  • 10. Relative This keyword lays out all elements as though the element were not positioned, and then adjust the element's position, without changing layout (and thus leaving a gap for the element where it would have been had it not been positioned (MDN) - The Element starts where it should have been - You can move it from it’s original position via (top, left, etc…) - limits the scope of absolutely positioned child elements
  • 11. Absolute Do not leave space for the element. Instead, position it at a specified position relative to its closest positioned ancestor if any, or otherwise relative to the initial containing block. Absolutely positioned boxes can have margins, and they do not collapse with any other margins. (MDN) - The element is out of the browser flow, meaning it won’t be affected by other elements. - Also it won’t affect other elements flow. - Will be relative to it closest non static parent, or to the html tag itself if none found.
  • 12. Fixed Do not leave space for the element. Instead, position it at a specified position relative to the screen's viewport and don't move it when scrolled. When printing, position it at that fixed position on every page. This value always create a new stacking context (MDN).
  • 13. Play Time - Positions https://plnkr.co/edit/JosJySkjT7V Ah4xuTp98?p=preview
  • 14. Collapsing Margins CSS, the adjoining margins of two or more boxes (which might or might not be siblings) can combine to form a single margin. Margins that combine this way are said to collapse, and the resulting combined margin is called a collapsed margin. (W3C SPEC) In short: when two topbottom margins touch each other they collapse 1. The higher margin is taken, and the smaller collapse to 0. 2. Negative and positive margins are added up rather than collapse. 3. Two Negative margins collapse, with the smaller one taken.
  • 15. Play Time - Collapsing Margins https://plnkr.co/edit/wvaBa6A7R 9snWJVxoIOP?p=preview
  • 16. Stacking context is the three-dimensional conceptualization of HTML elements along an imaginary z-axis relative to the user who is assumed to be facing the viewport or the webpage. HTML elements occupy this space in priority order based on element attributes. (MDN) Elements Order without z-index, are formed by the HTML hierarchy: 1. Last elements in HTML order will be displayed on top. 2. Positioned Elements have higher priority over static elements, which is strong then html order. 3rd Dimension, stacking context
  • 17. Play Time - Stacking Context no z-index. https://plnkr.co/edit/9ygOvS1BiB qsyatxcCML?p=preview
  • 18. Positioning and assigning a z-index value to an HTML element creates a stacking context, (as does assigning non-full opacity). Stacking contexts can be contained in other stacking contexts, and together create a hierarchy of stacking contexts. Each stacking context is completely independent from its siblings: only descendant elements are considered when stacking is processed. Each stacking context is self-contained: after the element's contents are stacked, the whole element is considered in the stacking order of the parent stacking context. Z-index & multi hierarchy stacks
  • 19. Play Time - Stacking Contexts https://plnkr.co/edit/tzW4NsFWA Hu0TLjAWEO1?p=preview MDN menu example
  • 20. Stacking Context - Summary 1. Stacking Context, is the concept of how the browser renders elements in the 3rd dimension (facing browser window). 2. By default context order is derived from html order (last element on top) 3. Default order gives priority for positioned elements over static elements. 4. Each context can host more contexts, each stacking context is self-contained. 5. New contexts are created by certain conditions a. HTML root
  • 21. Other Worth Knowing... 1. Css Transform 2. Css Pseudo Elements, check this 3. MDN, anytime you are not sure about what's going on...

Editor's Notes

  • #4: https://github.com/vasanthk/css-refresher-notes
  • #5: https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Introduction
  • #6: https://developer.mozilla.org/en-US/docs/Web/CSS/float
  • #8: https://developer.mozilla.org/en-US/docs/Web/CSS/float
  • #9: https://github.com/vasanthk/css-refresher-notes#positioning https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Introduction
  • #10: https://github.com/vasanthk/css-refresher-notes#positioning https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Introduction
  • #11: https://github.com/vasanthk/css-refresher-notes#positioning https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Introduction
  • #12: https://github.com/vasanthk/css-refresher-notes#positioning https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Introduction
  • #13: https://github.com/vasanthk/css-refresher-notes#positioning https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Introduction
  • #17: https://github.com/vasanthk/css-refresher-notes#positioning https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Introduction
  • #19: https://github.com/vasanthk/css-refresher-notes#positioning https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Introduction
  • #21: https://developer.mozilla.org/en-US/docs/Web/CSS/float