html - CSS animation using ::before class extends beyond the div
问题描述
I've added a slide animation to my portfolio website homepage, and I can't figure out how or why it is extending before the confines of the div it's attached to. On hover to extends left and right of the div.
Website is http://www.helencalderon.co.uk/
And the styles I'm using are
.card {
background-color: #fff;
position: relative;
border: 2px solid #d6d2d2;
margin-bottom: 2.8125%;
max-width: 714px
}
@media only screen and (min-width: 714px) {
.card {
margin:0 auto 2.8125% auto
}
}
@media only screen and (min-width: 1280px) {
.card {
display:flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
flex-direction: row;
max-width: none
}
}
.card::before {
position: absolute;
top: 0;
left: -100%;
z-index: 2;
display: block;
content: '';
width: 50%;
height: 100%;
background: linear-gradient(to right, rgba(255,255,255,0) 0%, rgba(255,255,255,0.3) 100%);
-webkit-transform: skewX(-25deg);
transform: skewX(-25deg)
}
.card:hover::before {
-webkit-animation: shine 2s;
animation: shine 2s
}
解决方案
您将 ::before 放置在容器的左侧left: -100%;
,并将其移动到left: 125%;
(因此在动画完成后将其放置在右侧 - 您将其移动到容器右侧 125% 的宽度)。使用transform: skewX(-25deg)
也使你的 ::before 更宽。
要切断所有从你身上逃脱的东西,.card
你可以添加overflow: hidden;
它。
推荐阅读
- c# - 阻塞事件处理程序
- c - 使用 int 数组作为 const unsigned char* 的输入
- c++ - 数组是如何排序的
- validation - 我的控制器忽略了我的自定义验证规则
- python - 如何找到整个盒子的每个小盒子中的点数
- django - Django rest 框架密码安全性
- python - Loading spatialite with python3's module under Windows
- c++ - Template function in constructor
- opengl-es - glGenBuffers fails to create one despite GL_NO_ERROR
- rxjs - convert a function into rxjs observable