What is CSS Box Model?
This sentence is a repetition from all around the web. Just so that we stay relevant : every element in web design is a rectangular box.
I'm thinking, if every element in web design is a box, then what can I do with these boxes?
- Change the size of the box.
- Change the color of the box.
- Change the background of the box.
Let us see how this box looks like:
Here's another one to calculate the height and width:
What is Block-level element?
- Block-level elements by default start on a new line and occupies full page width.
- Width and height properties are respected to block-level elements.
- Using display property, block-level elements can be converted to block-inline, inline, etc.
- Few block-level elements are div, p, pre, h1,h2,ul,ol.
What is inline element?
- Inline elements by default occupies only required width based on content size.
- Width and height properties are not respected/applicable to inline elements.
- Using display property, inline elements can be converted to block, block-inline, etc.
- Few inline elements are a,span, img, i.
Difference between Block and Inline elements.
- Block-level elements by default start on a new line and occupies full page width. But, Inline elements by default occupies only required width based on content size.
- Width and height properties are applicable to block-level element but not to inline elements.
- Inline elements can be placed inside the block-level element, but block-level elements can not be placed inside the inline element.
- Following padding and margin properties don’t affect inline elements
- padding-top
- padding-bottom
- margin-top
- margin-bottom Remaining padding and margin properties only affects inline elements.