It is true that original height and width of the element along with padding, margin is respected and rendered without any compromise in display:block, display:inline block and display:float
But when it comes to display:inline
, the element is not rendered in it's original height and width, the width and height of the content depends on the font size and content length.
(A) Talking about the padding and margin , like a normal text padding , padding and margin are allowed horizontally but not vertically. It might seem inline element's height and width increased after adding padding and margin but in real, content box size is always constant in this case with child text size. The main role of margin is to maintain space with surrounding element, since there is no space in between so, no margin is applied.
(B) And also, when you inspect the box model, padding also exist there, but the real gist of padding is to push the border away from content which also seem exist but we can't say border is pushed away, in reality border is destroyed because border is to prevent the element from intercrossing by surrounding element, so padding is not existed. You can see in horizontal padding, as it increases surrounding element are also pushed away.
I would suggest to go through this 2 code and come back again to explanation , mainly two points(A and B) ,
https://jsfiddle.net/d89Wd/
and my own version,
HTML code
<div class="inline-block">Inline-Block</div>
<div class="block">Block</div>
<div class="inline">Inline</div>
<div class="float">Float</div>
CSS code
.inline{
display:inline;
font-size: 10px;
border: 1px solid red;
}
.inline-block{
display:inline-block;
}
.block{
display:block;
}
/* .float{
float:left;
} */
div{
background-color:blue;
color:white;
height:100px;
width:200px;
padding:10px;
margin-bottom:10px;
}
I sandwiched the inline element between block and float , ..I maintained the bottom margin of all div as 10px,. I changed the font size because I told you earlier height of the inline element is rendered as height of the text font.
I will suggest to copy this code and run it into Firefox and then inspect its box model. You will see bottom margin of inline block , block and so then float exists but not of the inline element.(I will say margin padding exists physically but not into effect, or they are not creating space or pushing border)
After that you can check whether horizontal margin exists or not for inline element by adding some text
HTML code
<div class="inline-block">Inline-Block</div>
<div class="block">Block</div>
<div class="inline">Inline</div>Hey mate, how is it going?
<div class="float">Float</div>
CSS code
.inline{
display:inline;
border: 1px solid red;
margin: 0px 20px 10px 0px;
padding: 15px 90px 15px 0px;
font-size: 10px;
}
.inline-block{
display:inline-block;
}
.block{
display:block;
}
/* .float{
float:left;
} */
div{
background-color:blue;
color:white;
height:100px;
width:200px;
margin-bottom:10px;
}