css 垂直居中,指定文本宽度换行,指定高度出滚动条

寻技术 Html/CSS 2023年09月07日 62
!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>
    #container {
      width: 400px;
      height: 400px;
      display: table;
    }

    #cell {
      display: table-cell;
      vertical-align: middle;
    }

    #cell_bk {
      display: table;
      overflow-wrap: break-word;
      table-layout: fixed;
      width: 20px;
    }

    .scroll {
      height: 30px;
      overflow-y: auto;
    }
  </style>
</head>

<body>
  <div id="container">
    <div id="cell">
      <div class="scroll">
        <p id="cell_bk">
          dfdffffffffffffffffffffffffffff
        </p>
      </div>
    </div>
  </div>
</body>

</html>

 

关闭

用微信“扫一扫”