{"id":6688,"date":"2018-09-02T04:57:48","date_gmt":"2018-09-02T08:57:48","guid":{"rendered":"http:\/\/local.brightwhiz\/?p=6688"},"modified":"2021-12-08T11:32:00","modified_gmt":"2021-12-08T16:32:00","slug":"disable-a-link-using-only-css-html","status":"publish","type":"post","link":"http:\/\/local.brightwhiz\/disable-a-link-using-only-css-html\/","title":{"rendered":"How to Disable a Link Using Only CSS and HTML"},"content":{"rendered":"\n
So the real question is why would you want to disable a link? Wouldn’t it just make sense to have a none link text in its place?<\/p>\n\n\n\n
Well, that could happen but as with anything web development, it is not that simple. You might want to disable a link based on certain conditions be it dynamic or served straight from the server in a disabled state.<\/p>\n\n\n\n
Whatever the case, the good news is that it is not complicated in the least of terms.<\/p>\n\n\n\n
CSS<\/a> allows us one of the simplest ways to get this done. It is lightweight, safe, and works with all major browsers whether JavaScript<\/a> is turned on or off.<\/p>\n\n\n\n You can simulate a disabled link by simply hiding the real URL with no link text then style it appropriately. From the example below, you can see how this can be achieved.<\/p>\n\n\n\n Your CSS can be as follows.<\/p>\n\n\n\n Now all you need to do is track the even that will flip the span and the A to be either adopt the inline or none display properties.<\/p>\n\n\n\nYou Could, of Course, Disable a Link by Simulating<\/h2>\n\n\n\n
<div class="disableable">\n <a class="toggleLink" href="example.php">Some Text<\/a>\n <span class="toggleLink">Some Text<\/span\n<\/div><\/code><\/pre>\n\n\n\n
.disableable a.toggleLink { display: inline; }\n.disableable span.toggleLink { display: none; }<\/code><\/pre>\n\n\n\n
Using the Pure CSS and HTML Solution<\/h2>\n\n\n\n