Home >Web Front-end >CSS Tutorial >Can CSS Achieve the \'target=_blank\' Functionality for External Links?

Can CSS Achieve the \'target=_blank\' Functionality for External Links?

Barbara Streisand
Barbara StreisandOriginal
2024-11-01 08:09:02832browse

Can CSS Achieve the

Achieving Target="_blank" Functionality in CSS for External Links

External links embedded in a website's top menu present a challenge when the desired behavior is to open them in new tabs. While HTML offers the "target=_blank" attribute to address this, one may wonder if CSS provides an equivalent solution.

Unfortunately, as elucidated by c69, pure CSS alone cannot replicate the exact functionality of "target=_blank." Despite this limitation, a viable workaround leveraging HTML exists.

In the section of the HTML document, one can employ the following base tag:

<code class="html"><head>
    <base target="_blank">
</head></code>

This effectively sets all page links that do not specify a target attribute to open in a new, blank window by default. Alternatively, a specific target attribute can be assigned to individual links as follows:

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

This will override any previously set base target value and ensure that the designated link opens in a new window.

The above is the detailed content of Can CSS Achieve the 'target=_blank' Functionality for External Links?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn