使用CSS显示div内容后淡出

KC *_*hai 7 html css css3

我正试图在按钮点击时显示通知.按钮单击实际上检查电子邮件验证.我知道要显示包含错误消息内容的div.但是,我想淡出错误信息,让我们说5秒后.我想用CSS实现它.以下是我的尝试,它隐藏了一切.请指教.

#signup-response{
    width: 50%;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
    background-color: #FF0000;
    margin-top: 20px;
    -webkit-transition: opacity 5s ease-in-out;
    -moz-transition: opacity 35s ease-in-out;
    -ms-transition: opacity 5s ease-in-out;
    -o-transition: opacity 5s ease-in-out;
     opacity: 0;
} 
Run Code Online (Sandbox Code Playgroud)

Ita*_*Gal 15

你可以用animation 例子.

设置为animation-delay您想要的时间.确保animation-fill-mode: forwards用于停止动画.

#signup-response{
    width: 50%;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
    background-color: #FF0000;
    margin-top: 20px;

     animation:signup-response 0.5s 1;
    -webkit-animation:signup-response 0.5s 1;
    animation-fill-mode: forwards;

    animation-delay:2s;
    -webkit-animation-delay:1s; /* Safari and Chrome */
    -webkit-animation-fill-mode: forwards;

} 

@keyframes signup-response{
    from {opacity :1;}
    to {opacity :0;}
}

@-webkit-keyframes signup-response{
    from {opacity :1;}
    to {opacity :0;}
}
Run Code Online (Sandbox Code Playgroud)


bro*_*aha 10

使用css3关键帧动画:

我已经包含了-webkit-前缀,但你要添加-moz,-ms以及-oanimationanimation-delay性内.error-message和上keyframes.

.error-message {
    -webkit-animation: fadeOut 2s forwards;
    animation: fadeOut 2s forwards;
    -webkit-animation-delay: 5s;
    animation-delay: 5s;
    background: red;
    color: white;
    padding: 10px;
    text-align: center;
}

@-webkit-keyframes fadeOut {
    from {opacity: 1;}
    to {opacity: 0;}
}

@keyframes fadeOut {
    from {opacity: 1;}
    to {opacity: 0;}
}
Run Code Online (Sandbox Code Playgroud)
<div class="error-message">
    <p>Some random text</p>
</div>
Run Code Online (Sandbox Code Playgroud)