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

Barbara Streisand
Release: 2024-11-01 08:09:02
Original
714 people have browsed it

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>
Copy after login

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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!