I have the following HTML content. I have multiple elements (e.g., div with id = one, two, three) inside a div container which is scrollable.
In each element, I need to use CSS position 'absolute' which position related to its parent div (i.e., class='Anchor').
The problem I am having is, when I scroll the outer container, none of the divs with an absolute position moved. My understanding of position 'absolute' is it is positioned relative to its parent DIV element. How can I make those 'absolute' position move as I scroll the outer container?
<div style="overflow-y: scroll">
<div>
<div class="Anchor" id="one">
<div style="position: absolute"> something </div>
<div style="position: absolute"> something else </div>
</div>
</div>
<div>
<div class="Anchor" id="two">
<div style="position: absolute"> something </div>
<div style="position: absolute"> something else </div>
</div>
</div>
<div>
<div class="Anchor" id="three">
<div style="position: absolute"> something </div>
<div style="position: absolute"> something else </div>
</div>
</div>
</div>
position: relative;
and the child divs that areposition: absolute;
will be placed relative to the position of their parent elements. – Tombstoneposition: relative
on the parent that you want them to anchor to. Absolutely positioned elements will be positioned relative to the nearest relatively positioned parent, butdiv
elements haveposition: static
by default. – Nepali<div>
s and 9</div>
s. A validator, like the W3 one, can check it. The result (when wrapped in an HTML document to reduce spurious errors) is "Error: End tag for body seen, but there were unclosed elements." and four times "Unclosed element div." (the former is a result of the latter). – Crawley