I have a fixed positioned DIV called Lightbox. My problem is that the close button doesn't stay on the top right, when I scroll the content.
How can I achieve that the close button stays on the top right corner?
.lightbox { position: fixed; background: white; top: 50%; left: 50%; width: 600px; height: 400px; border: 1px solid black; margin-left: -300px; margin-top: -200px; z-index: 10000; overflow-y: auto; } .close-btn { position: absolute; top: 0; right: 0; background: black; color: white; font-weight: bold; border-radius: 100%; width: 20px; height: 20px; text-align: center; } .item { width: 250px; display: inline-block; border: 1px solid blue; height: 300px; background: lightblue; } <div class="lightbox"> <div class="close-btn">x</div> <div class="items"> <div class="item">Item</div> <div class="item">Item</div> <div class="item">Item</div> <div class="item">Item</div> </div> </div>
close-button.