鍍金池/ 問答/人工智能  HTML/ 加了absolute之后,span 這個行級元素的 text-align、wid

加了absolute之后,span 這個行級元素的 text-align、width等就生效了,請問這是為什么?

如題:

加了 position:absolute 之后,span 這個行級元素的 text-align、width、height 就生效了,請問這是為什么?

代碼:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    body {
      margin: 0;
    }
    .box {
      margin: 15% auto;
      width: 200px;
      height: 200px;
      box-sizing: border-box;
      border: 1px solid darkblue;
    }
    .text {
      /* 加上position后,生效了,相當于 display: block; */
      position: absolute;
      width: 200px;
      height: 200px;
      text-align: center;
      line-height: 200px;
    }
  </style>
</head>
<body>
  <div class="box">
    <span class="text">letter</span>
  </div>
</body>
</html>
回答
編輯回答
維他命

position:absolute 之后,span為display:block;

2017年8月20日 02:17
編輯回答
柒槿年

加上 position:absolute后,元素會被默認當成塊級元素對待

2018年4月7日 12:37