I'm creating a page that has two div elements directly above a bit of text that I want to create an anchor to. One of the div elements is display:none above a certain screen size, while the other div element is display:block, like so:
<div class="hidden"><!-- This div class is set to display:none; in CSS -->
<!-- Div content -->
</div>
<div class="show"><!-- This div class is set to display:none; in CSS -->
<!-- Div content -->
</div>
<a name="anchor"></a>
<h2>Paragraph heading</h2>
<p>Paragraph that I want to anchor to</p>
When I put the anchor as shown in the above example, it actually appears below the paragraph heading. Is it allowed to put two anchors of the same name, if one of the divs is display:none, like this:
<div class="hidden">
<!-- Div content -->
<a name="anchor"></a>
</div>
<div class="show">
<!-- Div content -->
<a name="anchor"></a>
</div>
<h2>Paragraph heading</h2>
<p>Paragraph that I want to anchor to</p>
Is there a way something like this is allowed? I have tested this, and the link to the anchor appears not to work -- is the HTML markup from the display:none div conflicting with the one in the display:block div, even if the one div element is not displayed by the browser?
The only example I could find on Stack Overflow was here: Anchor to element within hidden div , and it seemed to relate more to javascript toggle than my question. Please let me know if there are answers elsewhere.