click below
click below
Normal Size Small Size show me how
CSS - Week 2
WTWD 210 - CSS Box Model & Positioning
| Term | Definition | Example |
|---|---|---|
| Box Model | Concept that explains the layout of HTML elements (margin, border, padding, content). | div { margin: 10px; padding: 5px; border: 1px solid black; } |
| Margin | Space outside the border of an element. | margin: 20px; |
| Padding | Space inside the border of an element. | padding: 10px; |
| Border | The area between the padding and margin. | border: 2px solid #000; |
| Width | Specifies the width of an element. | width: 100px; |
| Height | Specifies the height of an element. | height: 200px; |
| Display | Specifies the display behavior of an element. | display: none; |
| Block | Block Elements; start on a new line and take up the full width available (by default) meaning they extend to the left and right as far as they can. Block-level elements create a block or box for their content. | display: block; |
| Inline | Inline Elements; do not start on a new line and only take up as much width as necessary. Inline elements do not force line breaks and allow other inline elements to sit beside them. They only take up as much space as their content requires. | display: inline; |
| Inline-Block | A hybrid between inline & block elements. Inline-block elements are formatted like inline elements where they sit next to each other on the same line. However they also accept width & height properties and can have margins & padding like block elements. | display: inline-block; |
| Flexbox | Flexbox is a one-dimensional layout method for arranging items in rows or columns. Items can grow or shrink to fill available space. | display: flex; |
| Grid | Grid is a two-dimensional layout method for creating complex responsive layouts. It allows for the precise control of rows and columns. | display: grid; |
| Position | Specifies the positioning method for an element (static, relative, absolute, fixed). | position: fixed; |
| Static Positioning | The default position for HTML elements. Elements are positioned according to the normal document flow and top, right, bottom, and left properties do not apply. | position: static; |
| Relative Positioning | The element is positioned relative to its normal position. The top, right, bottom, and left properties will offset it from its original position without affecting the layout of surrounding elements. | position: relative; top: 10px; |
| Absolute Positioning | The element is positioned relative to its nearest positioned ancestor (other than static) or relative to the initial containing block if no positioned ancestor is found. The top, right, bottom, and left properties are used to specify the offsets. | position: absolute; top: 20px; left: 30px; |
| Fixed Positioning | The element is positioned relative to the viewport which means it always stays in the same place even when the page is scrolled. The top, right, bottom, and left properties are used to specify the offsets. | position: fixed; top: 0; right: 0; |
| Float | Specifies whether an element should float to the left or right of its container. | float: left; |
| Clear | Specifies what elements can float beside the cleared element. | clear: both; |