I have read the [W3Schools][1] and they said
display: inline-block, the top and bottom margins/paddings are respected, but with display: inline they are not.
But, I have try to set the margin and padding to display: inline , it’s work!!
That make me so confuse what I’m doing wrong or what condition that I didn’t know.
Can someone explain me for this happening, Thank you.
3
Answers
Better check with https://www.w3.org/standards/.
W3schools.com is not recommended and outdated.
Inline
Check the code snippet. If used on the menu item, the a tag will not span to full width. So you need to exactly click on the link word to navigate. For a menu item, it is better if we click anywhere in that block. With applied css from the image, you can see though the margin left and right are given, it is applied. but the margin top and bottom are not applied.
Note: width rule is not applied since it is inline;
Inline Block
As the a tag spans to full width of the space, you can click on anywhere in the line, so the link will be navigated. Also you can see the margin top and bottom are applied. You can see the brown colored border around the element, which denotes the margin
When to use Inline
This is from my experience, if you have a running text and you want to alert the style of particular word (in the example considered the word highlight) use inline, so that the css rule does not affect the original para tag.
(for testing purpose, change the margin top and bottom of class highlight and you can see the whole para position will be moved, implies, the para tag style is also altered)
Reference: https://developer.mozilla.org/en-US/docs/Web/CSS/display
inline
inline-block
Play around with them below and see that margin and padding has some effects on both cases: