* {
margin:0;
padding:0;
}
.container {
font-size:20px;
line-height:100px;
border: 1px solid;
background-color: lightblue;
}
p {
display: inline;
background: coral;
line-height:50px;
}
<div class="container">
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit.</p>
</div>
In this example, the line-height of the child-element is 50px, but because it's inline, the line-height does not expand the content-box of the element. The size of the container remains the size of its line-height - 100px.
* {
margin:0;
padding:0;
}
.container {
font-size:20px;
line-height:100px;
border: 1px solid;
background-color: lightblue;
}
p {
display: block;
background: coral;
line-height:50px;
}
<div class="container">
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit.</p>
</div>
In this example, i have only changed the display property of the child-element from inline to block, and now its content-box has expanded because of the line-height, however, the container has collapsed to fit the element inside. I don't understand what happens to the line-height of the container? Why doesn't the container remain 100px?
I know that if i enter some text, the container will expand again to 100px, since the line-height of that text will be 100px. For example:
* {
margin:0;
padding:0;
}
.container {
font-size:20px;
line-height:100px;
border: 1px solid;
background-color: lightblue;
}
p {
display: block;
background: coral;
line-height:50px;
}
<div class="container">gfgfg
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit.</p>
</div>
..but why is that text not necessary when the child-element is inline?