css - 如果盒子模型不受影响,为什么在翻译元素时会发生溢出?

标签 css css-transforms

对我来说,将变换应用于元素始终意味着盒子模型没有移动,而元素只是在视觉上移动。

我想知道这是如何处理溢出的。如果元素的盒子模型没有被移动,那么浏览器如何知道元素正在脱离其父盒子?

.outer {
  width: 200px;
  height: 200px;
  background-color: blue;
  overflow: scroll;
}

.inner {
  width: 100px;
  height: 100px;
  transform: translateY(110%);
  background-color: red;
}
<div class='outer'>
  <div class='inner'>
  </div>
</div>

最佳答案

您是正确的,因为转换不会影响框布局,但是 the spec makes an exception for overflow :

For elements whose layout is governed by the CSS box model, the transform property does not affect the flow of the content surrounding the transformed element. However, the extent of the overflow area takes into account transformed elements. This behavior is similar to what happens when elements are offset via relative positioning. Therefore, if the value of the ‘overflow’ property is ‘scroll’ or ‘auto’, scrollbars will appear as needed to see content that is transformed outside the visible area.

关于css - 如果盒子模型不受影响,为什么在翻译元素时会发生溢出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28397868/

相关文章:

html - 导航子菜单创建空白

html - 跨浏览器/缩放响应悬停效果

css - Materialize:以 % 设置的 translateY 转换在 Safari 中不稳定

css - 倾斜div时防止从左向右滚动

css - 在悬停时缩放一个圆圈,保持边框的宽度

html - CSS : Position Text over image in Flexbox

javascript - Twitter 嵌入 - 如何覆盖 CSS

css - 转换和堆叠顺序

html - CSS 动画/变换离开屏幕

html - 使用 HTML5/CSS3 刷新页面将其定向到特定的 div?