gpt4 book ai didi

html - 我怎样才能将这个按钮设置为随着过渡出现

转载 作者:行者123 更新时间:2023-11-28 17:42:21 25 4
gpt4 key购买 nike

在我现在的代码中,按钮最初是可见的,随着过渡,它会隐藏在框后面。我想要的是“我的按钮最初应该被隐藏并且应该随着过渡出现”。提前致谢..附言没有 jQuery

<!DOCTYPE HTML>
<body>
<div id="anim">

</div>
<input type="button" value="this should be behind" id="btn" />

</body>
</html>

<style>

#anim{
z-index: 1;
position: absolute;
width: 300px;
height: 200px;
background-color: red;
-webkit-transition: all 2s;
-moz-transition: all 2s;
-ms-transition: all 2s;
-o-transition: all 2s;
transition: all 2s;
}

#anim:hover{
height:400px
}

#btn{
z-index: -1;
position:fixed;
margin-top: 300px;

}

</style>

最佳答案

您可以使用 adjacent sibling selector 设置悬停按钮的不透明度,而无需更改文档的结构。 .

方法如下:

#anim:hover + #btn
{
opacity: 1;
}

编辑:您还可以使用按钮上的 transition-delay 延迟此操作:

#btn
{
opacity: 0;
transition-delay: 700ms;
z-index: 2;
position:fixed;
margin-top: 300px;
}

下面是完整的 CSS,因为还进行了一些更改以最初隐藏按钮,并正确设置 z-index 属性。

JSFiddle here .

#anim{
z-index: 1;
position: absolute;
width: 300px;
height: 200px;
background-color: red;
-webkit-transition: all 2s;
-moz-transition: all 2s;
-ms-transition: all 2s;
-o-transition: all 2s;
transition: all 2s;
}

#anim:hover{
height:400px
}

#anim:hover + #btn{
opacity: 1;
}

#btn{
opacity: 0;
transition-delay: 700ms;
z-index: 2;
position:fixed;
margin-top: 300px;
}

关于html - 我怎样才能将这个按钮设置为随着过渡出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23868028/

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