Javascript-форум (https://javascript.ru/forum/)
-   (X)HTML/CSS (https://javascript.ru/forum/xhtml-html-css/)
-   -   @keyframes - нужен совет (https://javascript.ru/forum/xhtml-html-css/79895-%40keyframes-nuzhen-sovet.html)

MOT 04.04.2020 22:20

@keyframes - нужен совет
 
Доброго времени суток! Я решил решить :) проблему резкого исчезновения окон, написанных на CSS:
<!DOCTYPE html>
<html>
<head>
<style>
#checkbox ~ #modal {
opacity: 0; 
animation: close 0.5s linear 1;
}
#checkbox:checked ~ #modal {
opacity: 1;
position: fixed;
width: 50%;
height: 70%;
background: linear-gradient(white, #216558);
left: 25%;
top: 15%;
border-radius: 25px;
padding: 15px;
animation: open 0.5s linear 1;
}
@keyframes close {
0% {
top: 15%;
}
100% {
top: -100%;
}
}
@keyframes open {
0% {
top: -100%;
}
100% {
top: 15%;
}
}
</style>
</head>
<body>
<input type="checkbox" id="checkbox">
<label for="checkbox">Открыть</label>
<div id="modal">
<span>типо контент</span><br>
<label for="checkbox">Закрыть</label>
</div>
</body>
</html>

НО:
1)Не работает @keyframes close :-? ;
2)Даже если бы @keyframes close работал, то при полной загрузке страницы это модальное окно появлялось бы и тут же исчезало.
В чём суть вопроса: нет ли способа избавится от пункта 2 при помощи CSS?

рони 04.04.2020 23:22

MOT,
может transition?

рони 04.04.2020 23:43

модальное окно transition
 
MOT,

<!DOCTYPE html>
<html>
<head>
<style>
#modal {
width: 50%;
height: 70%;
background: linear-gradient(white, #216558);
left: 0;
top: -180%;
bottom: 0;
right: 0;
margin: auto;
border-radius: 25px;
padding: 15px;
opacity: .1;
position: fixed;
transition: top .5s linear 1s, opacity 2s;
}
#checkbox:checked ~ #modal {
transition: top .5s linear .3s, opacity 1s .8s;
top: 0;
opacity: 1;
}

</style>
</head>
<body>
<input type="checkbox" id="checkbox">
<label for="checkbox">Открыть</label>
<div id="modal">
<span>типо контент</span><br>
<label for="checkbox">Закрыть</label>
</div>
</body>
</html>

MOT 05.04.2020 09:12

Спасибо :)


Часовой пояс GMT +3, время: 04:15.