html - 变形后的 child 包含奇怪的 parent 宽度

标签 html css transform

我有一个简单的 HTML 标记:

<div class="parent">
    <div class="child">
    </div>
</div>

transform: translate(-100%); 将子元素移出视口(viewport),但父元素宽度不随子元素移动:

这是我简化的 CSS:

.parent {
    position: fixed;
    top: 20%;
    left: 0;
}

.parent .child {
    height: 300px;
    width: 500px;
    background: orange;
    transform: translate(-100%);
    -webkit-transform: translate(-100%);
    -moz-transform: translate(-100%);
    -o-transform: translate(-100%);
}

看看:

enter image description here

最佳答案

当转换和元素时,它的父元素不受影响。这就是 CSS 转换应该如何工作的。来自 Using CSS transforms :

By modifying the coordinate space, CSS transforms change the shape and position of the affected content without disrupting the normal document flow.

关于html - 变形后的 child 包含奇怪的 parent 宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37203744/

相关文章:

javascript - 使用 Intern 通过 CSS 选择器 ID 输入字段进行选择

qt - 如何将 QPixmap 转换为矩阵

jQuery css ('transform' ) 不返回任何内容

html - 谷歌地图 100% 高度不工作

javascript - 叠加层正在扩展到视口(viewport)之外

javascript - 如何使用 CSS3 准确展开一个 8 边的盒子?

css - 右侧的 HTML/CSS : Boostrap3 div placement with 2 on left, 1

ios - 转换不适用于 IOS

javascript - 位置 :absolute div inside another position:absolute div and making them position:fixed

javascript - 循环 dom 元素以获取属性值