Answer the question
In order to leave comments, you need to log in
How to make a block with position:fixed scroll?
Good afternoon!
There is a page http://new_bnews.zed.kz/ru/faq
It has a list of questions. The answers appear in a popup window. The window is set to position:fixed with a padding of 60 pixels from the top of the screen.
The problem is that some answers are too long, so the popup doesn't fit on the screen. But the way it is set to position:fixed, the window will not scroll.
If you set position:absolute to it, then it will be positioned relative to the top of the site, and this is not suitable, because you can open the answer to some lower question, and it (the answer) will open outside of visibility somewhere at the top. And it is necessary that everything be 60 pixels exactly from the top of the screen.
How can this problem be solved?
Thanks in advance!
Answer the question
In order to leave comments, you need to log in
Change structure:
<div class="popupbg" id="popupbg">
<div class="answer-popup"> </div>
</div>
.popupbg{
position: fixed;
height: 100%;
width: 100%;
left: 0;
top: 0;
overflow-y: scroll;
padding: 100px 0;
}
.answer-popup{
position: absolute;
left: 50%;
transform: translateX(-50%);
}
Make the popup absolute. But when opening a popup, call the following function:
var scrolled = $(window).scrollTop()+60;
$('твойпопап').css('top', scrolled);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question