Jump to content

CSS hyperlink?

Go to solution Solved by ladybug,
On 3/21/2022 at 7:44 PM, C2dan88 said:

What link you are trying to modify? Woocomerce has its own templates located in wp-content/plugins/woocommerce/templates/

oh that makes sense. So I need to search for that in the database probably. I need to edit html code in one of the templates to fix a hyperlink to work right with my website

4 hours ago, stefanmz said:

Hey can I change the href of hyperlink in css? Add a new destination and overwrite it?

This reminds me of:
image.png.e4405c978bbbfb9597c39d732bb09c66.png

🤣

Anyhow, you need to learn the basics Stefan...
I see your posts and I gotta say if you keep learning how to become a developer just by following tutorials and reading forum posts... your knowledge will be like Swiss cheese:

image.png.8783848f57cd194c11e96ff936b23c14.png

Full of holes, and as time goes by it will be even harder to go back and learn it properly.

 

The answer to your question is simple: no.
CSS = Cascading Style Sheets, a style sheet language, purpose of which is to describe the presentation of a document...
With CSS (alone) you can change how the hyperlink looks, but you can't change where it points to (href).

 

Link to comment
https://linustechtips.com/topic/1418417-css-hyperlink/#findComment-15306894
Share on other sites

Link to post
Share on other sites

38 minutes ago, Biohazard777 said:

This reminds me of:
image.png.e4405c978bbbfb9597c39d732bb09c66.png

🤣

Anyhow, you need to learn the basics Stefan...
I see your posts and I gotta say if you keep learning how to become a developer just by following tutorials and reading forum posts... your knowledge will be like Swiss cheese:

image.png.8783848f57cd194c11e96ff936b23c14.png

Full of holes, and as time goes by it will be even harder to go back and learn it properly.

 

The answer to your question is simple: no.
CSS = Cascading Style Sheets, a style sheet language, purpose of which is to describe the presentation of a document...
With CSS (alone) you can change how the hyperlink looks, but you can't change where it points to (href).

 

I mean I kinda know already that you can't but for some reason I think people on the internet might know more than me and conjure up some magic way to do it that for some reason, me who have already written an entire website using only html and css and have some good knowledge about them both overlooked. Anyway thanks for the Swiss joke that was hilarious! 😄

Link to comment
https://linustechtips.com/topic/1418417-css-hyperlink/#findComment-15306922
Share on other sites

Link to post
Share on other sites

You can change it using javascript, and with CSS you could make it appear to change by hiding and showing different elements, so you could create a new link, then hide the old one using display:none. But using plain CSS to change the href of an <a> tag is not possible.

 

However, it is possible to change the src of media on a page using CSS (fonts, images, borders, backgrounds etc).

Link to comment
https://linustechtips.com/topic/1418417-css-hyperlink/#findComment-15307623
Share on other sites

Link to post
Share on other sites

Another thing to note is that, even if you *could* change it with CSS -- I've seen some bizarre demonstrations for CSS functionality -- you *really* don't want to do it that way.

CSS is all about presentation.  No meaningful changes to the data itself should be coming in from CSS.  HTML is the data (more or less, there's some metadata around presentation, along with sometimes some presentation itself), and CSS is the presentation.  Trying to edit the HTML (which is the only way to change the actual link) via CSS is like trying to change the canvas of a painting by applying chemicals.

Link to comment
https://linustechtips.com/topic/1418417-css-hyperlink/#findComment-15308494
Share on other sites

Link to post
Share on other sites

You can do it easily with Javascript 

 

have the function run on on page load complete or something like that, enumerate all the < a > tags, check the href property of each tag and if it matches that url, replace the href and text to your desired content.

Should be able to add Javascript code to your wordpress easily. 

 

ex see QuerySelectorAll : https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll

do something like this 

 

const matches = document.querySelectorAll("a[href]");

then enumerate with a forEach or for ()  and compared the href value with your url and change if needed.

 

Link to comment
https://linustechtips.com/topic/1418417-css-hyperlink/#findComment-15308601
Share on other sites

Link to post
Share on other sites

On 3/17/2022 at 10:55 AM, mariushm said:

You can do it easily with Javascript 

 

have the function run on on page load complete or something like that, enumerate all the < a > tags, check the href property of each tag and if it matches that url, replace the href and text to your desired content.

Should be able to add Javascript code to your wordpress easily. 

 

ex see QuerySelectorAll : https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll

do something like this 

 

const matches = document.querySelectorAll("a[href]");

then enumerate with a forEach or for ()  and compared the href value with your url and change if needed.

 

 

On 3/16/2022 at 7:07 PM, FlappyBoobs said:

You can change it using javascript, and with CSS you could make it appear to change by hiding and showing different elements, so you could create a new link, then hide the old one using display:none. But using plain CSS to change the href of an <a> tag is not possible.

 

However, it is possible to change the src of media on a page using CSS (fonts, images, borders, backgrounds etc).

Thank you for your answers! Yeah the best way is undeniably javascript or directly through html however because of time constraints and lazyness xD I will not do it with javascript I just don't want to bother. So unless I find where the heck the page is in the database,because I searched for it but didn't find it, and change the html code there, unless I do that, I am going to use css tricks, thanks for the suggestion by the way I didn't think about the display property trick. Anyway unless someone knows more about woocommerce and knows how to find the shop page in the database where the other pages are,becuase I couldn't find it there, I am going css

Link to comment
https://linustechtips.com/topic/1418417-css-hyperlink/#findComment-15313686
Share on other sites

Link to post
Share on other sites

On 3/21/2022 at 7:44 PM, C2dan88 said:

What link you are trying to modify? Woocomerce has its own templates located in wp-content/plugins/woocommerce/templates/

oh that makes sense. So I need to search for that in the database probably. I need to edit html code in one of the templates to fix a hyperlink to work right with my website

Link to comment
https://linustechtips.com/topic/1418417-css-hyperlink/#findComment-15318064
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×