So, I have some css3 popups/modals that I'm working with. I'm mostly pretty happy with the way that they work, but after the modal is closed the page scrolls back up to the top and I'm not sure why this is happening.
You can see the behavior here Here's a snippet of the html
<div class="flip">
<div class="front">
<img src="images/SDG_ICONS/SDG01.png" alt="No Poverty" />
</div>
<div class="back">
<ul>
<a href="#ared-no-poverty"><li>ARED</li></a>
<a href="#agrocenta-no-poverty"><li>AgroCenta</li></a>
<a href="#tilly-no-poverty"><li>Tilly's Farm</li></a>
</ul>
</div>
</div>
<div id="ared-no-poverty" class="overlay">
<div class="popup">
<h2>ARED</h2>
<a class="close" href="#"> ×</a>
<p class="popup">Some text in here</p>
</div>
And here's the css I'm using for the popup/modals
.popup {
margin: 70px auto;
padding: 20px;
background: #fff;
border-radius: 5px;
width: 30%;
position: relative;
transition: all 5s ease-in-out;
z-index: 2;
}
.popup h2 {
margin-top: 0;
color: #333;
font-family: Tahoma, Arial, sans-serif;
}
img.popup{
width:150px;
height: auto;
float:left;
}
.popup p{
width:auto;
margin:0;
}
.popup p:nth-child(2){
padding-top:5px;
}
.popup .close {
position: absolute;
top: 20px;
right: 30px;
transition: all 200ms;
font-size: 30px;
font-weight: bold;
text-decoration: none;
color: #333;
}
.popup .close:hover {
color: #06D85F;
}
.popup .content {
max-height: 30%;
overflow: auto;
}
.overlay {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(88, 120, 33, 0.7); /*0,0,0*/
transition: opacity 500ms;
visibility: hidden;
opacity: 0;
z-index: 2;
}
.overlay:target {
visibility: visible;
opacity: 1;
}
So, how can I keep the at the same scroll position as when the popup was called and what is causing the modal to scroll to the top?