将默认类添加到一组链接

时间:2012-06-08 18:09:23

标签: html css

我想在一堆链接中添加一个默认类。而不是

<a href=1 class=text1>1</a>
<a href=2 class=text1>2</a>
<a href=3 class=text1>3</a>
<a href=4 class=text1>4</a>
<a href=5 class=text1>5</a>
<a href=6 class=text1>6</a>
<a href=7 class=text1>7</a>

我想做

<span class=text1>
<a href=1 >2</a>
<a href=2 >3</a>
<a href=3 >4</a>
<a href=4 >5</a>
<a href=5 >6</a>
<a href=6 >7</a>
<a href=7 >8</a>
</span>

text1类类似于:

a.text1:link { color: white; text-decoration: underline ;}
a.text1:active { color: white; text-decoration: underline ;}
a.text1:visited { color: white; text-decoration: underline ;}
a.text1:hover { color: white; text-decoration: underline ;  }

然而,第二种选择似乎不起作用。我是愚蠢的还是有任何方法可以在像这样的小组中制作一堆链接吗?

3 个答案:

答案 0 :(得分:3)

使用:

span.text1 a:link { color: white; text-decoration: underline ;}
span.text1 a:active { color: white; text-decoration: underline ;}
span.text1 a:visited { color: white; text-decoration: underline ;}
span.text1 a:hover { color: white; text-decoration: underline ;  }

答案 1 :(得分:1)

只需使用:

span.text1 a:link {
    /* css */
}

或者,如有必要,只选择第一级后代,即“直接”子项:

span.text1 > a:link {
    /* css */
}

答案 2 :(得分:1)

它不起作用。 试试这个

span.text1 a:link { color: white; text-decoration: underline ;}
span.text1 a:active { color: white; text-decoration: underline ;}
span.text1 a:visited { color: white; text-decoration: underline ;}
span.text1 a:hover { color: white; text-decoration: underline ;  }