如何设置target =“_ blank”锚点的样式?

时间:2015-03-26 14:36:48

标签: css

我一直在寻找一种方法来改变我网站上有一个目标的链接的CSS:_blank;请注意,我只能在css而不是js中执行此操作。谢谢。

示例:

<style>
a{ color : blue }
a:[target=_blank]{ color : green}
</style>

<a href="someplace.html">link1</a>
<a href="someplace.html" target="_blank">link2</a>

Link1为蓝色,Link2为绿色。

2 个答案:

答案 0 :(得分:4)

尝试fiddle

a[target=_blank]{ color : green}

&#13;
&#13;
a{ color : blue }
a[target=_blank]{ color : green}
&#13;
<a href="someplace.html">link1</a>
<a href="someplace.html" target="_blank">link2</a>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

CSS3提供了基于属性的类,您可以使用它们来定位它们。

在您的情况下,您希望匹配确切的字符串,请使用

a[target="_blank"] {
  // styles here
  background: red;
}

一些类似的变体:

a[href^="http:"] {
     // targets only links starting with http
}

img[src$=".png"] {
     // matches all images png images alone
}

a[href*="home"] {
       // matches all links which contains home in the link
}
相关问题