
Originally Posted by
Stevie D
The easy solution to that is to add cursor:default; into the CSS for your 'current page' style. That way, although it will still function as a link if they click on it, there's less encouragement for them to do so. Although TBH once you've styled the 'current page' link differently, not many people will try to click on it anyway.
Yes that's true, although I guess that won't help keyboard users as you'd need to turn focus off as well but of course the link will still be followed if selected.
For mouse users you could stop this happening by using :after to place an element on top to stop it being clicked.
e.g.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>No Clickable link on current item</title>
<style type="text/css">
ul#nav {
list-style:none;
margin:10px;
padding:0;
float:left
}
ul#nav li {
float:left;
border:1px solid #000;
margin-left:-1px;
position:relative;
}
ul#nav a {
float:left;
width:5em;
height:2em;
line-height:2em;
text-decoration:none;
text-align:center;
background:#ffc;
color:#000;
}
ul#nav a:hover,
ul#nav li.current a {
color:#fff;
background:#f00;
}
ul#nav li.current:after {
position:absolute;
display:block;/* safari bug*/
content:" ";
left:0;
top:0;
right:0;
bottom:0;
z-index:999;
}
ul#nav li.current a { cursor:default }
</style>
</head>
<body>
<ul id="nav">
<li class="current"><a href="page1.htm">Link 1</a></li>
<li><a href="page2.htm">Link 2</a></li>
<li><a href="page3.htm">Link 3</a></li>
<li><a href="page4.htm">Link 4</a></li>
<li><a href="page5.htm">Link 5</a></li>
<li><a href="page6.htm">Link 6</a></li>
</ul>
</body>
</html>
(IE8+ only)
Of course keyboard users could still activate the link which is why I prefer to use a span or other element instead of an anchor.
Bookmarks