<!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