html - 如何隐藏延伸到其容器之外的元素?
问题描述
我有一个动画蓝色框,它应该来自右侧并输入其父 div。我试图找出一种方法使该框在进入父 div 之前不可见。最外层的 div(灰色)由框架控制,因此基本上无法访问。
.outer-div-no-access {
background: gray;
position:relative;
height:100vh;
padding: 10px;
}
.parent-div {
position: relative;
background-color: yellow;
border: 2px solid green;
height: 200px;
width: 50%;
}
.child-div {
position: relative;
height: 25%;
background-color: lightblue;
animation-name: example;
animation-duration: 2s;
left: 25%;
}
@keyframes example {
from {
left: 100%;
}
to {
left: 25%;
}
}
<html>
<body>
<div class="outer-div-no-access">
<div class="parent-div">
<div class="child-div">
</div>
</div>
</div>
</body>
</html>
解决方案
在父级上使用溢出:隐藏:
.outer-div-no-access {
background: gray;
position:relative;
height:100vh;
padding: 10px;
}
.parent-div {
overflow: hidden;
position: relative;
background-color: yellow;
border: 2px solid green;
height: 200px;
width: 50%;
}
.child-div {
position: relative;
height: 25%;
background-color: lightblue;
animation-name: example;
animation-duration: 2s;
left: 25%;
}
@keyframes example {
from {
left: 100%;
}
to {
left: 25%;
}
}
<html>
<body>
<div class="outer-div-no-access">
<div class="parent-div">
<div class="child-div">
</div>
</div>
</div>
</body>
</html>
推荐阅读
- jenkins - 如何在 Jenkins 的 changeSet 中获取修订/提交 ID
- xcode - React Native - 多个目标
- mongodb - MongoDB索引一个可能不存在的字段
- postgresql - 时区从冬季更改为夏季 rails 根据新时区显示时间戳
- php - 如何从相关表中获取所有行,包括数据透视表中的列?
- jakarta-ee - 服务器崩溃和重启时的 CDI 事件观察器处理
- javascript - 使这个 dob 计算器工作的步骤是什么?JavaScript
- ef-core-2.1 - abp.io 项目模板中的多个 DbContext
- here-api - 如何为我的 getroute 请求获取 RouteId?
- java - 为什么在简单的现实生活中需要在 java 中重载?