<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>文字隐藏</title>
</head>
<style>
.content-box {
width: 100px;
border: 5px solid red;
padding: 10px;
box-sizing: content-box;
text-overflow: ellipsis;
overflow: hidden;
}
.border-box {
width: 100px;
border: 5px solid red;
padding: 10px;
box-sizing: border-box;
text-overflow: ellipsis;
overflow: hidden;
margin-bottom: 10px;
}
</style>
<body>
borderBox
<div class="border-box">
99999991
</div>
contentBox
<div class="content-box">
999999999991
</div>
<script>
// 对于borderBox 只要scrollWidth > clientWidth 那么就代表hidden了
const borderBox = document.querySelector('.border-box')
const contentBox = document.querySelector('.content-box')
console.dir(borderBox)
console.log('borderBox', borderBox.scrollWidth, borderBox.clientWidth) // zdz-log
console.dir(contentBox)
console.log('contentBox',contentBox.scrollWidth,contentBox.clientWidth); // zdz-log
</script>
</body>
</html>