On my web page, I have a spinner component that can be added to different parts of the page as needed. The spinner is always centered according to its parent, which is in relative position, while the spinner itself is absolute. However, the issue arises when some of the spinner containers are scrollable; in these cases, the spinner is no longer centered. While I know that using position fixed can center content for scrolled elements, this only works when the content should be centered on the entire page.
In my specific scenario, is there a way to achieve proper centering regardless of scrolling? An example image and code snippet are provided below:
https://i.sstatic.net/rR6g0.jpg
html,
body {
height: 98%;
}
.header {
position: relative;
overflow: auto;
height: 26%;
border: 1px solid grey;
margin-bottom: 2%;
}
/* Remaining CSS properties included */
<body>
<div class="header">
Lorem ipsum dolor sit amet, consectetur adipiscing elit...
<div class="spinner-wrapper">
<div class="spinner"></div>
</div>
</div>
<div class="main">
<div class="content">
Content
<div class="spinner-wrapper">
<div class="spinner"></div>
</div>
</div>
<div class="side-menu">
Side menu
<div class="spinner-wrapper">
<div class="spinner"></div>
</div>
</div>
</div>
</body>