Fundamentals of Browser Rendering Css Overview PT 1

22
The fundamentals of the browser rendering - part 1 By Barak Drechsler

Transcript of Fundamentals of Browser Rendering Css Overview PT 1

Page 1: Fundamentals of Browser Rendering Css Overview PT 1

The fundamentals of the browser

rendering - part 1By Barak Drechsler

Page 2: Fundamentals of Browser Rendering Css Overview PT 1

How css feels like...

Page 3: Fundamentals of Browser Rendering Css Overview PT 1

How css should feel...

Page 4: Fundamentals of Browser Rendering Css Overview PT 1

Web rendering flow

1. Process HTML markup and build the DOM tree.

2. Process CSS markup and build the CSSOM tree.

3. Combine the DOM and CSSOM into a render tree.

4. Run layout on the render tree to compute geometry of each node.

5. Paint the individual nodes to the screen.

Page 5: Fundamentals of Browser Rendering Css Overview PT 1
Page 6: Fundamentals of Browser Rendering Css Overview PT 1

The web building blocks are boxes

The CSS box model is the foundation of layout on the Web — each element is represented as a rectangular box, with the box's content, padding, border, and margin built up around one another like the layers of an onion.

As a browser renders a web page layout, it works out what styles are applied to the content of each box, how big the surrounding onion layers are, and where the boxes sit in relation to one another.

Page 7: Fundamentals of Browser Rendering Css Overview PT 1

The Box Model(content-box)

Page 8: Fundamentals of Browser Rendering Css Overview PT 1

The Box Model(border-box)

Page 9: Fundamentals of Browser Rendering Css Overview PT 1

Play Time - Box Models https://plnkr.co/edit/XNYbkiuXiSH49haIhdCv?p=preview

Page 10: Fundamentals of Browser Rendering Css Overview PT 1

Quick recap for the box properties

Overflow: defaults to visible, requires the box to have explicit height, or percentage to be calculated by parent element height.

Height: isn’t inherited! Any div in the way can interfere with it children heights

Border, padding, margin, are straightforward...

Page 11: Fundamentals of Browser Rendering Css Overview PT 1

Play Time - Height & Overflow https://plnkr.co/edit/23kJgu8u1AssnLlHVt27?p=preview

Page 12: Fundamentals of Browser Rendering Css Overview PT 1

Boxes types...

Block

Inline

Inline-block

none

(table, flex, grid)

Page 13: Fundamentals of Browser Rendering Css Overview PT 1

Block

Block level elements do not sit inline, but break past them. If no width is set, will expand naturally to fill its parent container.

Can have margins and/or padding.

If no height is set, will expand naturally to fit its child elements (assuming they are not floated or positioned). So, for a block element, it’s not necessary to give it a set width or to give it a width of 100%.

Ignores the vertical-align property.

Page 14: Fundamentals of Browser Rendering Css Overview PT 1

Inline

Default value for elements. Think of elements like span, b or em

Will ignore top and bottom margin/padding settings, but will apply left and right margin/padding. Only moves horizontally, not vertically.

Is subject to vertical-align property.

Will ignore width and height properties.

If floated left or right, will automatically become a block-level element, subject to all block characteristics.

Page 15: Fundamentals of Browser Rendering Css Overview PT 1

Inline Block

Very similar to inline to its parents in that it will set inline with the natural flow of text.

Very similar to block to its children in that it can have a width and height and its content can move vertically.

Think of a display:block element that has been rendered (or converted to an image) and then placed in the document inline

Margin and paddings work properly.

Width and height will be respected.

Page 16: Fundamentals of Browser Rendering Css Overview PT 1

Play Time - inline, block, inline-block

https://codepen.io/barakdr/pen/GNrBRg

Page 17: Fundamentals of Browser Rendering Css Overview PT 1

Summary

1. We discussed the browser rendering flow DOM + CSSOM => Render Tree => Layout => paint.

2. Each element is box.

3. It height 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)

Page 18: Fundamentals of Browser Rendering Css Overview PT 1

The road ahead...

We now have to see, how can we affect how elements are being put together.

The ways to manipulate browser layout:

Floats

Positioning - next session

CSS tables

Flexbox

Grid

Page 19: Fundamentals of Browser Rendering Css Overview PT 1

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)

Page 20: Fundamentals of Browser Rendering Css Overview PT 1

Play Time - floats https://plnkr.co/edit/Bz4hS2E9emkbr3fvts16?p=preview

Page 21: Fundamentals of Browser Rendering Css Overview PT 1

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.

Page 22: Fundamentals of Browser Rendering Css Overview PT 1

Questions?