Every page on my website so far has the same navigation menu and it's working fine. (I copied it only for sceptical readers, but it's just a normal navigation menu that works fine.)
<ul class="navigation">
<li><a href="SampleCard.html">
<div>FREE Yarn<br>Sample Card</div>
</a></li>
<li><a href="index.html">
<div>Home</div>
</a></li>
<li><a href="SpinningFibre.html" class="active">
<div>Spinning<br>Fibre</div>
</a></li>
<li><a href="MillSpun.html">
<div>Mill Spun<br>Yarn</div>
</a></li>
<li><a href="HandSpun.html">
<div>Hand Spun<br>Yarn</div>
</a></li>
<li><a href="Books.html">
<div>Books</div>
</a></li>
<li><a href="WhyBuy.html">
<div>Why Buy<br>Rare Breeds?</div>
</a></li>
<li><a href="AboutUs.html">
<div>About Us</div>
</a></li>
<li><a href="ContactUs.html">
<div>Contact Us</div>
</a></li>
<li><a href="PostagePrice.html">
<div>Postage<br>Prices</div>
</a></li>
</ul>
Notice that this particular page is "Spinning Fibre" so "SpinningFibre.html" has the "active" class. (This becomes important later.)
The biggest down side with this technique is that every time I want to change the navigation menu, I need to copy and paste the same change into every... single... page... I... have... made.
I saw a technique that allows me to embed one html file into another. For example:
<div w3-include-html="navigation.html"></div>
I'm eager to try it, as it will make future edits to my navigation so much easier. However, how can I make the CSS know which link is the active link, so it can format accordingly?
I have learned a lot of PHP, so any solutions that require PHP code are welcome.
Edit Below: (This was formally an answer, but I think this is the way I should have posted the results)
Adam's answer, although definitely on the money, would never run exactly as written. Still, I was able to see past the typos to the gold hidden beneath. However, any future reader looking over this may not be able to, so here is the fully working version of the navigation code posted in the question.
(I also used echo, but only because I'm more familiar with how to use echo, and the limitations of it, than I am with Adam's method.)
File name "navigation.php":
<ul class="navigation">
<li><a href="SampleCard.html"<?php if($currentPage == 'SampleCard'){echo 'class="active"';}?>>
<div>FREE Yarn<br>Sample Card</div>
</a></li>
<li><a href="index.html"<?php if($currentPage == 'index'){echo 'class="active"';}?>>
<div>Home</div>
</a></li>
<li><a href="SpinningFibre.html"<?php if($currentPage == 'SpinningFibre'){echo 'class="active"';}?>>
<div>Spinning<br>Fibre</div>
</a></li>
<li><a href="MillSpun.html"<?php if($currentPage == 'MillSpun'){echo 'class="active"';}?>>
<div>Mill Spun<br>Yarn</div>
</a></li>
<li><a href="HandSpun.html"<?php if($currentPage == 'HandSpun'){echo 'class="active"';}?>>
<div>Hand Spun<br>Yarn</div>
</a></li>
<li><a href="Books.html"<?php if($currentPage == 'Books'){echo 'class="active"';}?>>
<div>Books</div>
</a></li>
<li><a href="WhyBuy.html"<?php if($currentPage == 'WhyBuy'){echo 'class="active"';}?>>
<div>Why Buy<br>Rare Breeds?</div>
</a></li>
<li><a href="AboutUs.html"<?php if($currentPage == 'AboutUs'){echo 'class="active"';}?>>
<div>About Us</div>
</a></li>
<li><a href="ContactUs.html"<?php if($currentPage == 'ContactUs'){echo 'class="active"';}?>>
<div>Contact Us</div>
</a></li>
<li><a href="PostagePrice.html"<?php if($currentPage == 'PostagePrice'){echo 'class="active"';}?>>
<div>Postage<br>Prices</div>
</a></li>
</ul>
You don't need to see my header (still needs tidying), but as soon as the body tag opens it looks like this (this example is the Spinning Fibre page):
<body>
<?php
$currentPage = 'SpinningFibre';
include 'navigation.php';
?>
It really works a treat. Thanks Adam.
(Now I am using the same method for all the headers.)