Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can't use JUST CSS to determine which page your user currently is - it just won't do it. You have to adjust your markup to add a hook of some kind that your CSS can use. Like so -</p> <pre><code>&lt;ul id="nav"&gt; &lt;li&gt;&lt;a href="about.html" class="here"&gt;About Us&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="contact.html"&gt;Contact&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>If you're building a static HTML site, you can manually change the HTML on each page to reflect the current page in the menu.</p> <p>If you're building something more complex, you will probably need to rely on PHP or JavaScript to figure out the current page. This script is a little old (it's from Jeremy Keith's "DOM Scripting"), but it will do the job:</p> <pre><code>function highlightPage(id){ //make sure DOM methods are understood if(!document.getElementsByTagName) return false; if(!document.getElementById) return false; if(!document.getElementById(id)) return false; var nav = document.getElementById(id); var links = nav.getElementsByTagName('a'); for (var i=0; i &lt; links.length; i++){ var linkurl = links[i].getAttribute('href'); var currenturl = window.location.href; //indexOf will return -1 on non-matches, so we're checking for a positive match if (currenturl.indexOf(linkurl) != -1) { links[i].className = "here"; var linktext = links[i].lastChild.nodeValue.toLowerCase(); document.body.setAttribute("id",linktext); } } } addLoadEvent(function(){ highlightPage('nav'); }); function addLoadEvent(func){ var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function(){ oldonload(); func(); } } } </code></pre> <p>This script would go in an <a href="http://www.quackit.com/javascript/tutorial/external_javascript_file.cfm" rel="nofollow">externally linked javascript file</a>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload