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!