CSS 溢出原理

标签 css overflow

来自 Mozilla 对“溢出”属性的描述:

Setting one axis to visible (the default) while setting the other to a different value results in visible behaving as auto.

我看不出这样做有什么好处,也看不到任何可以避免的问题。为什么是规范的这一部分?

最佳答案

考虑这个我们在两个方向都有溢出的例子:

.box {
 border:1px solid;
 width:200px;
 height:200px;
}
.box:before {
  content:"";
  display:block;
  height:150%;
  width:150%;
  background:red;
}
<div class="box">

</div>

添加 overflow-x:scroll;overflow-y:visible 意味着我们隐藏了水平溢出,同时有一个滚动来查看它并保持垂直溢出可见但是我们在这里有一个问题,因为什么垂直溢出可以覆盖滚动条(你不能再滚动看到一些内容)或者相反(滚动会隐藏一些我们看不到的内容)

enter image description here

滚动重叠内容说明

因此,如果其中一个属性设置为 scrollauto(它应该生成一个滚动),另一个需要做同样的事情,因为它不能溢出可见。

.box {
 border:1px solid;
 width:200px;
 height:200px;
 overflow-x:scroll;
 overflow-y:visible;
}
.box:before {
  content:"";
  display:block;
  height:150%;
  width:150%;
  background:red;
}
<div class="box">

</div>

来自规范:

Computed value: as specified, except with visible/clip computing to auto/hidden (respectively) if one of overflow-x or overflow-y is neither visible nor clip ref

关于CSS 溢出原理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57007497/

相关文章:

html - overflow-x 拒绝显示?

html - 如何使用 CSS 居中和裁剪图像以始终显示为方形?

html - 如何在不使用 !important 或 javascript 的情况下覆盖内联 CSS?

jquery - 将鼠标悬停在 <a> 标签上时子菜单不会停留

javascript - CSS3 模糊效果导致悬停时出现奇怪的阴影

css - 如何自动滚动显示:table when overflow?

html - 带有字段集的两列页面

java - 仅使用整数求两个数字的平均值

表格单元格中的 CSS 文本溢出?

c# - LINQ to SQL 转换溢出