首页 > 其他分享 >div 实现类似textarea的拖动大小的效果

div 实现类似textarea的拖动大小的效果

时间:2023-03-25 12:38:18浏览次数:40  
标签:console log textarea 拖动 height color div 30px


<!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>css</title>
  <style>
    .mdiv {
      width: 200px;
      height: 30px;
      border: 1px solid #616161;
      text-indent: 12px;
      line-height: 30px;
      /* resize: vertical; */
      resize: horizontal;
      overflow: auto;
    }

    .mdiv:focus {
      border-color: blueviolet;
      outline: none;
    }

    .btn {
      width: 120px;
      height: 30px;
      text-align: center;
      line-height: 30px;
      background-color: blueviolet;
      color: #fff;
      margin-top: 20px;
      cursor: pointer;
    }

  </style>
</head>

<body>
  <div class="mdiv" contenteditable></div>
  <div class="btn">按钮</div>

  <script>
    document.getElementsByClassName('btn')[0].addEventListener('click', () => {
      const div = document.getElementsByClassName('mdiv')[0];
      console.log(div.innerText);
      console.log(div.offsetWidth);
      console.log(div.offsetHeight);
    })
  </script>
</body>

</html>

overflow

div 实现类似textarea的拖动大小的效果_css


标签:console,log,textarea,拖动,height,color,div,30px
From: https://blog.51cto.com/u_12836588/6149253

相关文章