Line-height is equal to height, why is it not centered, talk about line-height

line-height is actually equivalent to the height of the content area

Combined with the following demo explanation: because box-sizing: border-box is set, so the content area is: 200-10*2 = 180px

If box-sizing: border-box is not set, or box-sizing: content-box is set, then this height is actually the height of content:
insert image description here

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    html,
    body {
    
    
      margin: 0;
      padding: 0;
    }
    .bos {
    
    
      box-sizing: border-box;
      height: 200px;
      width: 200px;
      background-color: aquamarine;
      border: 10px solid red;
      line-height: 180px;
      text-align: center;
    }
  </style>
</head>
<body>
  <div class="bos">
    <span>凡夫俗子</span>
  </div>
  <script>
  </script>
</body>
</html>

Code result:
insert image description here

Guess you like

Origin blog.csdn.net/weixin_43131046/article/details/123013103