Please refer - https://jsfiddle.net/59a15a9d/
span {
height: 200px;
width:200px;
background: red;
display: inline-block;
border: 2px solid green;
margin: 4px;
/*float: left*/ /*Second uncomment this*/
}
<span>hello</span>
<span>hello
<!-- <p>asd</p> --> <!-- first uncomment this -->
</span>
I have 2 span elements vertically aligned with "inline-block" CSS. Now in the JSFiddle follow the comments. I have a few questions:
When you remove the first comment, you add a
<p>
element inside the 2nd span and then the 1st span automatically is misaligned. Why?Vertical-align property will fix it. How?
When you remove the second comment, instead of a vertical align it just floats
<span>
left and again they are aligned correctly. What magic did float have on the spans?
Not related to above, one more quick question.
When position absolute/fixed is added to a span element, why does it become a block element?