Explain your understanding of the box model and how you would tell the browser in CSS to render your layout in different box models.
Quiz · CSS
Medium
3 min
css
The CSS box model describes the rectangular boxes that are generated for elements in the document tree and laid out according to the visual formatting model. Each box has a content area (e.g. text, an image, etc.) and optional surrounding padding, border, and margin areas.
The CSS box model is responsible for calculating:
- How much space a block element takes up.
- Whether or not borders and/or margins overlap, or collapse.
- A box's dimensions.
The box model has the following rules:
- The dimensions of a block element are calculated by
width,height,padding,borders, andmargins. - If no
heightis specified, a block element will be as high as the content it contains, pluspadding(unless there are floats, for which see below). - If no
widthis specified, a non-floated block element will expand to fit the width of its parent minuspadding. - The
heightof an element is calculated by the content'sheight. - The
widthof an element is calculated by the content'swidth. - By default,
paddings andborders are not part of thewidthandheightof an element.
Adapted from the Front End Interview Handbook by Yangshun Tay and contributors (MIT License). Source
Spotted a mistake or a rights concern? Report an issue