Water Posted February 19, 2011 Share Posted February 19, 2011 So, I've got a navigation bar, it works well, changes colour when the mouse hovers over it and when it is the current page.However, one minor problem that still applies with it- the current page is still clickable. Its greyed out so I want it to be converted into just a unclickable button whilst on that particular page.Is there any easy bit of CSS code to null such things? Link to comment Share on other sites More sharing options...
Fmdpa Posted February 19, 2011 Share Posted February 19, 2011 CSS cannot alter the functionality of elements - it is for styling elements. Is there any reason you can't remove the link on the current page? Link to comment Share on other sites More sharing options...
Water Posted February 19, 2011 Author Share Posted February 19, 2011 CSS cannot alter the functionality of elements—it is for styling elements. Is there any reason you can't remove the link on the current page?Can do. Just seems a bit cooler to do it this way.Also getting rid fo the link and changing it to just text gets rid of all the CSS formatting as well. Link to comment Share on other sites More sharing options...
Fmdpa Posted February 19, 2011 Share Posted February 19, 2011 I'd recommend doing that, but if you are looking for options here is another one. You could add an ID to the current page link. Then with Javascript, you could prevent that link from working: <a href="/current.php" id="current">Current Page</a><script>link = document.getElementById('current');link.onclick = function() { return false;}</script> Link to comment Share on other sites More sharing options...
shadowayex Posted February 19, 2011 Share Posted February 19, 2011 Can do. Just seems a bit cooler to do it this way.Also getting rid fo the link and changing it to just text gets rid of all the CSS formatting as well.You could set the href to either "#" or "java script: void(0);" if you wanted to keep the link but just make sure it doesn't go anywhere. Link to comment Share on other sites More sharing options...
Water Posted February 19, 2011 Author Share Posted February 19, 2011 Its weird..I'm not even sure why it isn't working just changing it into text. The CSS just speaks of text, not of links, and lists can be for text just fine normally. hmm You could set the href to either "#" or "java script: void(0);" if you wanted to keep the link but just make sure it doesn't go anywhere.that tries to take me to url/java script: void (i.e. page not found error)Also...it still make the mouse hovering over the area turn into a clikable link. Even if it did nothing it spoils the style a little, I want it dead. Link to comment Share on other sites More sharing options...
shadowayex Posted February 19, 2011 Share Posted February 19, 2011 that tries to take me to url/java script: void (i.e. page not found error)Also...it still make the mouse hovering over the area turn into a clikable link. Even if it did nothing it spoils the style a little, I want it dead.Hmm, remove the space, so it's<a href="java script: void(0);">whatever</a> I don't know why I put a space.Anyway, if you want it to not to hover effects or anything, you're going to need to do more work. Something like a.disabled:link, a.disabled:visited, a.disabled:hover, a.disabled:active{ // your style} Should work fine.Edit: It seems this forum put a space in java script for me. Just remove it when you copy it. Link to comment Share on other sites More sharing options...
Water Posted February 19, 2011 Author Share Posted February 19, 2011 Ohhhh bum. I was being stupid. deleted the <a href> from before it to make it font but I forgot that I needed the <a> for my css. Gah. Oh well, figured it.Now to try and figure out how to stop the active one highlighting., Link to comment Share on other sites More sharing options...
Water Posted February 19, 2011 Author Share Posted February 19, 2011 And that was elementary too...Note to self: Don't be trying to mess on with anything technical past midnight.Thanks all. Link to comment Share on other sites More sharing options...
Fmdpa Posted February 19, 2011 Share Posted February 19, 2011 Couldn't you just remove the href attribute? It would disable the link, but the element would remain. It should not affect the styles at all, unless you are targeting a[href] elements, which is unlikely. Link to comment Share on other sites More sharing options...
thescientist Posted February 19, 2011 Share Posted February 19, 2011 just turn the a for that particular "active" page into a span. (a particular benefit being they're both inline), and if you are somehow targeting the a elements specifically in the CSS, you could just add span to the style definition in the CSS (I'm just assuming your structure): #menu a, span{ //normal style}#menu a:hover, span{ //hover style}etc or just add whatever class you have made and put it on the span instead of the a.if that's confusing, just provide a link or code and we can try it out. Link to comment Share on other sites More sharing options...
jeffman Posted February 19, 2011 Share Posted February 19, 2011 I agree that using JavaScript to remove the href attribute is the simplest solution. In every browser I've tried, this inactivates all pseudo-classes, including :link. You might need to change the className if you have a ruleset for the plain <a> element (without a pseudoclass). That would be a very simple addition. Alternatively, you could change the value of the link's style.color property right in the script and not bother with a separate class.You'll also want an automated system for identifying the correct link. This makes it possible to use the same script in every document without having to customize it for every page. (Maybe you have this already. I don't recall it being mentioned.)I tested this code in IE7-8, Mozilla, Webkit, and Opera: function disableThisLink () { var i, myLinks = document.getElementsByTagName('a'), len = myLinks.length; for(i = 0; i < len; ++i) { if (myLinks[i].href == location.href) { myLinks[i].removeAttribute("href"); // myLinks[i].className = "something"; // only if you need it break; } }}window.onload = disableThisLink; Obviously, you're free to execute the function in any way that you want to, as long as the links have already been added to the DOM. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.