Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add target="_blank" in CSS

I have external links in the top menu of my website.

I want to open these links in new tabs. I could achieve it using target=_blank in HTML. Is there a similar CSS property or anything else?

like image 553
Husnain Ali Avatar asked Jun 24 '13 17:06

Husnain Ali


People also ask

Can you add target _blank in CSS?

Unfortunately, no. In 2013, there is no way to do it with pure CSS.

What is target _blank in CSS?

target="_blank" is a special keyword that will open links in a new tab every time. target="blank" will open the first-clicked link in a new tab, but any future links that share target="blank" will open in that same newly-opened tab.

How do you add a target _blank to a URL?

Conclusion. You can use the target="_blank" attribute if you want your users to click on a link that opens up a new browser tab. The target="_blank" attribute is used inside the opening anchor tag like this.

How do I add a target attribute?

a target=”_blank” Open in New Browser Tab (or Window) The target attribute specifies where the linked document will open when the link is clicked. The default is the current window. If target="_blank" , the linked document will open in a new tab or (on older browsers) a new window.


1 Answers

As c69 mentioned there is no way to do it with pure CSS.

but you can use HTML instead:

use

<head>     <base target="_blank"> </head> 

in your HTML <head> tag for making all of page links which not include target attribute to be opened in a new blank window by default. otherwise you can set target attribute for each link like this:

    <a href="/yourlink.html" target="_blank">test-link</a> 

and it will override

<head>     <base target="_blank"> </head> 

tag if it was defined previously.

like image 105
Mojtaba Rezaeian Avatar answered Sep 29 '22 10:09

Mojtaba Rezaeian