-7

I want a popup with a close button. Which will display after 5 seconds and after fully page loaded.

Is there any CSS tricks?

Darshan Rathod
  • 591
  • 4
  • 16
  • 2
    This is not possible with CSS only. – node_modules Jul 31 '17 at 08:01
  • 1
    to show some elements after delay you most use javascript or jquery – aidinMC Jul 31 '17 at 08:01
  • 2
    you can go for CSS3 animations, use the animation-delay property Here is the link https://www.w3schools.com/css/css3_animations.asp – Jefree Sujit Jul 31 '17 at 08:01
  • 1
    @C0dekid i'm pretty sure it is possible. – Philipp Sander Jul 31 '17 at 08:02
  • You can't do it without javascript. You will need CSS to customize your popup and javascript for timer and event – sheplu Jul 31 '17 at 08:02
  • It's not about whether it's possible or not with CSS only, Stack Overflow community helps, don't work for other, you should at least show what you tried.. – Alburkerk Jul 31 '17 at 08:12
  • it can be done with only CSS ( has some downsides though ) . But in the future you need to put some effort in solving your issues and then come to SO as a last resort – Mihai T Jul 31 '17 at 08:36
  • @Alburkerk First and Foremost I am not WORKING FOR OTHERS I am new at CSS at the time of asking so I searched google but didn't find relevant to my question then I ask here.... – Darshan Rathod Dec 26 '18 at 13:47

4 Answers4

4

You can use css animation to make the div's scale 0 in the first 5s after page load and then after 5s it will change automatically to scale 1 because it's the default scale value

@keyframes pop
{
  0%{transform:scale(0);}
  100%{transform:scale(0);}
}
<div style="animation: pop 5s;">this div will be shown exactly 5s after page load</div>
Tomer Wolberg
  • 1,256
  • 10
  • 22
  • While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – doydoy Jul 31 '17 at 13:18
1

You can try this

.container {
  width: 100vw;
  height: 100vh;
  background: lightblue;
  position: relative;
}

.popup {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 200px;
  height: 200px;
  background: white;
  opacity: 0;
  animation: popup .5s 5s ease forwards;
}
@keyframes popup {
 from {opacity: 0; }
 to{opacity: 1; }
}
<div class="container">
  <div class="popup">Popup</div>
</div>
Gerard
  • 15,418
  • 5
  • 30
  • 52
0

I'm not really sure if this will works on you or not

but somehow a guy out there is asked nearly same (but different context) case. you can try to check this

note : correct me if im wrong

nandermind
  • 19
  • 5
0

It can be done with CSS only, using animations and checkbox hack

I suggest in the future you try and do it yourself and at least post what you have tried or some sample code. This is not a code making site. We help you get to a solution but we need to see that you have tried something.

Anyway, i had some free time and wanted to help you. But this won't happen often on SO

So here it is. Using silibing selectors ( +, ~ ), CSS animations and checkbox click hack

See below

body {
  margin: 0
}

input:checked,
input:checked + .popMe,
input:checked ~ .overlay {
  display: none;
}

input {
  position: fixed;
  right: 15px;
  top:30%;
  opacity: 0;
  animation-name: justopac;
  animation-delay: 1s;
  animation-duration: 0.3s;
  animation-fill-mode: forwards;
  animation-timing-function: ease-out;
  z-index: 2;
}

.popMe {
  height: 150px;
  width: 150px;
  left: 50%;
  top: 50%;
  transform: scale(0) translate(-50%, -50%);
  position: fixed;
  background: red;
  animation-name: popMe;
  animation-delay: 1s;
  animation-duration: 0.3s;
  animation-fill-mode: forwards;
  animation-timing-function: ease-out;
  transform-origin: left;
  z-index: 2;
}

.overlay {
  position: fixed;
  animation-name: justopac;
  animation-delay: 1s;
  animation-duration: 0.3s;
  animation-fill-mode: forwards;
  animation-timing-function: ease-out;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  opacity: 0;
}

@keyframes justopac {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}

@keyframes popMe {
  0% {
    transform: scale(0) translate(-50%, -50%);
  }
  100% {
    transform: scale(1) translate(-50%, -50%);
  }
}
<input type="checkbox">
<div class="popMe">
  <p>
    This is a popup
  </p>
</div>
<div class="overlay">

</div>

<div class="content">
  Lorem ipsum dolor sit amet, curabitur eu a duis vitae odio, ac consectetuer conubia at, donec ante aliquam at, placerat neque leo, ac turpis accumsan. Aenean viverra pellentesque aliquet, tincidunt dolor consequat lorem dolorum mauris, amet bibendum sed
  lacus, sapien duis nullam. Pellentesque nunc laoreet id egestas integer ac. Proin dis tristique sodales mollis incididunt. Est phasellus elit libero, fermentum suspendisse enim convallis mauris sed vulputate, ac aliquam integer quis consectetuer pellentesque,
  wisi urna velit pharetra pellentesque, dictum velit nec metus vitae. Neque tincidunt nec, eu et ligula etiam sit aliquam wisi. Cupiditate scelerisque ipsum pellentesque maecenas quam, ipsum nec augue suscipit, tincidunt mi ac ut risus urna tristique.
  Fermentum vel eros, posuere convallis. Est lectus morbi leo mollis, pede nihil pharetra venenatis, sit est fermentum.
</div>
Mihai T
  • 17,254
  • 2
  • 23
  • 32