I'm working with angular 2, but this questions is mostly about css (I'm using bootstrap 3). I've got 2 divs (leftDiv and rightDiv) like this:
<div class="row">
<div *ngFor="let address of addresses">
<div class="card" id="leftDiv">
<h5 class="card-text">{{address.name}}</h5>
<h5 class="card-text">{{address.street}}</h5>
<h5 class="card-text">{{address.city}}</h5>
</div>
</div>
<!-- bunch of code -->
<div class="col-md-6" id="rightDiv">
<!-- should appear at the top of current view -->
</div>
</div>
So, there are a bunch of cards with addresses on the left side (leftDiv). The rightDiv appears only with the click of a button, and also only 1 at a time. What happens at the moment is, that the rightDiv appears at the top of the page (so if you scrolled down far enough you don't even see it). What it should do is appear at the top of the current view.
position: fixed;
does that, but then it sticks to the top of the screen, which i don't want (i should just appear and stay there). I've also tried to set the position of the leftDiv and rightDiv to relative and absolute, but that seems only to work if one is the parent of the other (which is not possible in my case).
Help would be greatly apppreciated.
Solution:
document.getElementById('rightDiv').style.top =
document.body.scrollTop.toString()+'px';
(See Top Answer)