Display Inline Block Text Inside Issue
I have been trying out display inline-block, everything worked out great if I didn't add anything into the divs but when I do the div collapsed and I don't know exactly why. Any id
Solution 1:
The issue is due to default vertical alignment of inline elements – baseline
, the text inside element affects it and pushes div to the bottom. Use vertical-align: top
, for example, to suppress this behavior.
Solution 2:
display:inline-block
creates a small gap, so add font-size:0
to parent. plus add vertical-align:top
since by default inline-block
is baseline
with all of this you have fixed your issue.
here is the snippet:
.caja {
background-color: gray;
width: 100px;
height: 100px;
border: 1px solid black;
margin: 5px;
}
.caja-grande {
background-color: gray;
border: 1px solid black;
padding: 5px;
width: 350px;
margin: 5px;
font-size: 0
}
.inline-block {
display: inline-block;
vertical-align: top;
font-size: 16px;
}
<divclass="caja"></div><divclass="caja-grande"><divclass="caja inline-block"><span>Hola mundo</span></div><divclass="caja inline-block"></div><divclass="caja inline-block"></div></div><divclass="caja inline-block"></div><divclass="caja inline-block"></div><divclass="caja"></div>
you can find more info (and options on how to solve this in other ways) in this article Fighting the Space Between Inline Block Elements
Solution 3:
Use overflow: hidden
at .inline-block
to make this work.
.inline-block{
display: inline-block;
overflow: hidden;
}
Post a Comment for "Display Inline Block Text Inside Issue"