Solved

CSS question related to hyperlinks

Posted on 2016-10-11
9
44 Views
Last Modified: 2016-10-11
Is it possible to style a hyperlink so that:

a) The hyperlink can be made non-clickable.
or
b) The style specifies a URL to override the a href declaration.

Thanks,
Steve
0
Comment
Question by:skbohler
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 41838407
Presuming straight HTML/CSS:
a) No.
b) No.

You could do something like that via javascript, or a back-end coding language (like ASP.Net).
0
 
LVL 20

Accepted Solution

by:
Russ Suter earned 500 total points
ID: 41838611
CSS only deals with style, not functionality. That being said, some styles do actually affect function and there are many tricks you can pull. The downside is that not all browsers interpret CSS the same way. You can sort of disable a link using the following CSS:
a.noclick
{
  pointer-events: none;
}

Open in new window

Then your markup:
<a href="http://www.experts-exchange.com" class="noclick">Experts Exchange</a>

Open in new window

However I'm not sure it will work across all browsers. It does work in Chrome.
Here's a list of browsers that support the pointer-events style: http://caniuse.com/#feat=pointer-events

The 2nd issue is much harder to get around. CSS can do lots of things, even add content but changing attributes is not something I've ever seen done with any real success. Javascript would be the way to do this.

So, the short answer to your questions in order are:
a) Yes (mostly)
b) No, use Javascript
0
 
LVL 53

Expert Comment

by:Julian Hansen
ID: 41838705
Begs the question if you can edit the HTML to add the class why not just remove the href ?
0
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 41838711
Yes, the acceptance of that as a solution makes no sense.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 20

Expert Comment

by:Russ Suter
ID: 41838733
How does the acceptance of the solution make no sense? It answers the questions asked. Whether or not the implementation is appropriate is a different topic.
0
 

Author Comment

by:skbohler
ID: 41838742
I want to dynamically change the class of the a tag depending on certain factors. If a certain flag is set, I want the link to be inactive. No HTML editing.
0
 
LVL 20

Expert Comment

by:Russ Suter
ID: 41838754
I'm curious. If you're assigning a class to an element aren't you editing the HTML anyway? Or do you have some other way of setting the flag outside the HTML markup?
0
 

Author Comment

by:skbohler
ID: 41838765
The flag will be set via a query to a database.
0
 
LVL 53

Expert Comment

by:Julian Hansen
ID: 41839058
Which implies the page is generated? In which case why generate the link in the first place?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Where to define breakpoints for responsive CSS 2 31
P tag not forcing line space 2 23
HTML Relative path 9 29
remove background quote mark from widget 6 24
So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now