Skip to content

Instantly share code, notes, and snippets.

@alejo4373
Last active April 13, 2021 02:44
Show Gist options
  • Save alejo4373/3d7fedf0efe9d18b80601a0bbfe8f649 to your computer and use it in GitHub Desktop.
Save alejo4373/3d7fedf0efe9d18b80601a0bbfe8f649 to your computer and use it in GitHub Desktop.
Notes from the CSS Box Model review session

The CSS Box Model

The CSS box model is the idea that all elements in HTML are boxes and each box has border. Each box/element then has a content area, padding area, border area and margin area. By default the content area will be as wide and as tall as the contents inside the element, and the padding, border and margins are 0 or the browser's defaults, which vary from browser to browser.

Key css box model properties

  • width
  • height
  • padding
  • margin
  • border

Other properties

  • box-sizing

Main Types of boxes

inline box/element

  • Done create line breaks after them
  • Occupies space necessary for it content
  • Appear on the same "line"
  • Not containers/Should not have children
  • Do not respect height and width css properties, but respect padding, border and margin.
  • Examples: <span>, <a>, <img>, <strong>

block box/element

  • Occupy all available width
  • As tall as its content.
  • Create a line break after them
  • Generally containers/Have other elements inside
  • Respect all css box model properties: height, width, padding, border, margin.
  • E.g. <div>, <h1>, <li>, <p>

flexbox

grid

Resouces

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment