The 3 Musketeers: inline, block & inline-block
A reference for box-model behavior three types of display components in CSS
let me tell a story about 3 fellas named inline, block and inline-block in the world of CSS.
I hope everybody is aware of the box model concept. Everything in HTML world is a box. That is why cats love HTML đ.
There are 3 components of a box:
à„° Dimension (Height and Width)
à„° Padding
à„° Border
à„° Margin
But those 3 fellas donât behave in the same way when it comes to width, height, padding, border, and margin. Let's talk to them one by one:
Dimension (width, height):
inline: See, I am very frugal when it comes to space. I will take as much width as much my child will need, no more no less. About height, I choose to follow my own rule. You can tell me about your choice but I am not going to give a damn đ!
block: Well, I like to have my place a Lil comfy. I will take the whole width if you donât tell me, otherwise I will follow whatever width and height you tell me đ.
inline-block: I choose to follow Mr. block.
Padding
inline: well there is a little caveat, I will follow the padding provided by you. âBut however, the vertical
padding
âthetop
andbottom
âmay bleed into the lines above and below an elementâ. You know I am frugal na?block: I will follow whatever you say, master.
inline-block: I choose to follow Mr. block đ.
Margin
inline: Okay okay you are askingâŠletâs do a favor for you. I will follow whatever horizontal margin you provide, but vertical margin, Nah! You give but I wonât take it! đ
block: I will follow whatever you say, master.
inline-block: Mr. block I am following you but you donât have any self-esteem đ.
Borders
inline: AhhâŠnow it is becoming irritation, okay I will follow you đ
block: I will follow whatever you say, master.
inline-block: I am following Mr. block đ„.
AhâŠthat was a productive interview. In a nutshell