gpt4 book ai didi

html - CSS - Div 不跟随动画父元素

转载 作者:太空宇宙 更新时间:2023-11-04 01:11:09 25 4
gpt4 key购买 nike

我正在尝试让一段文本覆盖动画(关键帧)图像。

到目前为止,我已经尝试过显示属性的组合,例如内联 block ,但没有成功。我还尝试调整位置,将标题和图像设置为相对和绝对。

我希望标题文本 (h4) 跟随它后面的动画图像。

html {
overflow: hidden;
}

body {
margin: 0;
overflow: hidden;
}

canvas {
display: block;
vertical-align: bottom;
}

h4 {
position: absolute;
background-color: red;
width: 128px;
display: inline-block;
color: white;
font-size: 24px;
}

.transactionBG {
position: absolute;
left: 0;
overflow: hidden;
}

.transaction {
width: 64px;
height: 64px;
position: absolute;
animation: upDown 1.5s alternate infinite ease-in-out;
}

@keyframes upDown {
to {
transform: translateY(100px);
}
}
<div class="transactionBG" style="top: 10%;left: 50%;width: 128px;height: 278px;">
<img class="transaction" src="https://seeklogo.com/images/I/instagram-circle-logo-E285122AB7-seeklogo.com.png" style="width: 102.4px; height: 102.4px;">
<h4>test</h4>
</div>

当前状态演示:http://jsfiddle.net/4huj31fb/2/

最佳答案

你只给了图像动画。移动这一行:

animation: upDown 1.5s alternate infinite ease-in-out;

.transactionBG选择器

html {
overflow: hidden;
}

body {
margin: 0;
overflow: hidden;
}

canvas {
display: block;
vertical-align: bottom;
}

h4 {
position: absolute;
background-color: red;
width: 128px;
display: inline-block;
color: white;
font-size: 24px;
}

.transactionBG {
position: absolute;
left: 0;
overflow: hidden;
animation: upDown 1.5s alternate infinite ease-in-out;
}

.transaction {
width: 64px;
height: 64px;
position: absolute;
}

@keyframes upDown {
to {
transform: translateY(100px);
}
}
<div class="transactionBG" style="top: 10%;left: 50%;width: 128px;height: 278px;">
<img class="transaction" src="https://seeklogo.com/images/I/instagram-circle-logo-E285122AB7-seeklogo.com.png" style="width: 102.4px; height: 102.4px;">
<h4>test</h4>
</div>

关于html - CSS - Div 不跟随动画父元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51181331/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com