A simple problem of line-height

in the process of writing HTML and CSS, I found that I didn"t understand line-height.
HTML Code:

<div class="p">
  <span class="c">Color</span>
</div>

CSS Code:

*{
  margin:0;
  padding:0
 }
.c{
  color:white;
  font-size:20px;
  line-height:40px;
  background:orange;
  display:block
}

effect:

The

code is very simple, the height of the span tag is 40px, but what I want to ask is, if you comment out the line display:block above, the height of the span tag is 22px, while the height of the div becomes 40px, and the range of background colors only includes the span tag
question:
if there is no display:block, line-height alone for 40px does not support the height of the span tag? But propped up the height of div to 40px?
Link: Link

Css
Nov.22,2021

take a look at the article by Zhang Xinxu:
some in-depth understanding and application of css line high line-height


this property affects the layout of row boxes. When applied to a block-level element, it defines the minimum distance rather than the maximum distance between baselines in that element.

span defaults to inline elements, and div defaults to block-level elements

The

span element is an inline element. When you remove the display:block, the display attribute of the span becomes the inline,inline attribute element that cannot set the width and height, which is determined by the element content, but line-height can be used to set the height of the inline element, so the div will be propped up to the 40px
line-height CSS attribute to set the amount of space for multiline elements, such as text. For block-level elements, it specifies the minimum height of the element row box (line boxes). For non-substituted inline elements, it is used to calculate the height of the line box (line box).


popular point: if you remove the span of display:block, you regard it as a text. You set the line height for the text, but the size of the text will not change, but the div wrapped in it will hold up to 40.

Menu