<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Overflow values</title>
<style>
body { font-family: system-ui, sans-serif; font-size: 14px; }
.row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.box {
width: 150px; height: 50px; padding: 8px;
border: 2px solid #2563eb; background: #eff6ff;
margin-bottom: 60px;
}
.visible { overflow: visible; }
.hidden { overflow: hidden; }
.scroll { overflow: scroll; }
.auto { overflow: auto; }
</style>
</head>
<body>
<div class="row">
<div class="box visible"><b>visible</b>: this text is longer than its box, which is only 50px tall, so it overflows.</div>
<div class="box hidden"><b>hidden</b>: this text is longer than its box, which is only 50px tall, so it overflows.</div>
<div class="box scroll"><b>scroll</b>: this text is longer than its box, which is only 50px tall, so it overflows.</div>
<div class="box auto"><b>auto</b>: this text is longer than its box, which is only 50px tall, so it overflows.</div>
</div>
</body>
</html>
值
你看到的效果
是否为滚动容器
visible(默认值)
内容溢出盒子,盖住后面的元素
否
hidden
在内边距边缘裁剪,没有滚动条(脚本仍可滚动)
是
clip
裁剪,而且完全不能滚动,脚本也不行
否
scroll
总是显示滚动条,即使内容放得下
是
auto
只在内容放不下时显示滚动条
是
在 macOS 和手机上,滚动条会叠加在内容上方并自动淡出,所以在你滚动之前,scroll 和 auto 看起来可能一模一样。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Ellipsis</title>
<style>
body { font-family: system-ui, sans-serif; }
.one-line {
width: 240px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
border: 1px solid #d1d5db; padding: 6px;
}
.three-lines {
width: 240px; margin-top: 12px;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
overflow: hidden;
border: 1px solid #d1d5db; padding: 6px;
}
</style>
</head>
<body>
<div class="one-line" id="one">A very long file name that will not fit in the box.pdf</div>
<div class="three-lines" id="three">This paragraph is longer than three lines. Only the first three lines are shown and the end of the third one becomes an ellipsis, which suits card previews and search results.</div>
</body>
</html>