Description of the setup
I'm building a website for a DnD campaign of mine in Django and using a modified version of this HTML5up.net page (CSS and JS is unchanged from stock). In my setup I have 2 pages, an index page (the HTML5up one) that people land on and "Character" pages that are hyperlinked to in the index page.
A jsfiddle to demonstrate the index page (without images) is here.
At the start the index page displays only the <header>
, while the hyperlinks are in the <article id="characters">
section, which is not visible in the beginning. These sections only become visible through clicking on their respective button e.g. <a href="#characters">Characters</a>
which jumps to the respective section.
My goal:
I want to be able to jump to not just the <article>
section, but I want to be able to open the <article>
AND jump to a specific hyperlink within it (e.g. the link to the character-page of "Zart"). With this I could create a button on character pages that lead back to the index page at exactly the position the user left the index page at.
My Problem :
Hyperlinking back to index and anchor jumping to an <article>
section (e.g. "characters") is easily doable with this :
<a href="LinkOfIndexPagePlaceholder#characters"> Back to Characters </a>
Hyperlinking back to index in a way that opens the article section AND jumps to the specific character (e.g. "Zart") in an article does not work with this, despite the anchor of an item (e.g. "Zart") having also the correct id (e.g. "Zart"):
<a href="LinkOfIndexPagePlaceholder#Zart"> Back to Characters </a>
In fact, I am entirely unable to anchor jump to the anchor with id "Zart" at all, as long as the article section of "character" isn't already being displayed.
If it is already being displayed (tested by changing the href of the "Add Character" Button in the jsfiddle to "#Zart") then I can jump to to that anchor, so the general way of jumping works. It is jumping to anchors that aren't being displayed (so in CSS "display:none") that is problematic. I need to somehow get that article section to be displayed before jumping.
How do I get it to work?
What I tried so far were the approaches discussed here. None of them worked for me. The first answer lead to the text and hyperlinks of all article sections to disappear, the second was already what I was trying to do.
Resources
Below is a shortened version of the HTML of the page.
I shortened it down to essential bits for the problem, so only a single entry and only the character section remain. To get the CSS, please download the page either from HTML5up or get its css files from filebin as zip. They are sadly too long to post here and I don't know which bits are the essential ones for this.
The HTML of the index page :
<!DOCTYPE HTML>
<!--
Dimension by HTML5 UP
html5up.net | @ajlkn
Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
-->
<html>
<head>
<title> Aldrune </title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/>
<link rel="stylesheet" href="{% static 'frontpage/assets/css/main.css' %}"/>
<link rel="stylesheet" href="{% static 'fontawesome47/css/font-awesome.min.css' %}">
<noscript>
<link rel="stylesheet" href="{% static 'frontpage/assets/css/noscript.css' %}"/>
</noscript>
</head>
<body class="is-preload">
<!-- Wrapper -->
<div id="wrapper">
<!-- Header -->
<header id="header">
<div class="logo">
<a class="icon"><span class="icon fa-gem"> </span></a>
</div>
<div class="content">
<div class="inner">
<h1>Aldrune</h1>
<p><b> A campaign made by X and recorded by Y</b></p>
</div>
</div>
<nav>
<ul> <!-- The anchor-jump buttons to <article> -->
<li><b><a href="#characters">Characters</a></b></li>
</ul>
</nav>
</header>
<!-- Main -->
<div id="main">
<!-- Characters article -->
<article id="characters">
<h2 class="major">Characters</h2>
<ul>
<li><a id="Zart" href="LinkToCharactersPage1"> Zart </a></li>
<li><a id="Zenevieva" href="LinkToCharactersPage2"> Zenevieva </a></li>
<li><a id="Zuxus" href="LinkToCharactersPage3"> Zuxus </a></li>
</ul>
</article>
</div>
</div>
<!-- Scripts -->
<script src="{% static 'frontpage/assets/js/jquery.min.js' %}"></script>
<script src="{% static 'frontpage/assets/js/browser.min.js' %}"></script>
<script src="{% static 'frontpage/assets/js/breakpoints.min.js' %}"></script>
<script src="{% static 'frontpage/assets/js/util.js' %}"></script>
<script src="{% static 'frontpage/assets/js/main.js' %}"></script>
</body>
</html>