将默认类添加到一组链接

时间:2021-07-30 03:48:01

I'm looking to add a default class to a bunch of links. So instead of

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

<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>

I want to do

我想要做

<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>

where the text1 class is something like:

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 ;  }

However the second option doesn't seem to work. Am i being stupid or is there any way to make a bunch of links in a group like this follow a class?

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

3 个解决方案

#1


3  

Use:

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 ;  }

#2


1  

Simply use:

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

Or, if necessary, select only the first-level descendants, the 'immediate' children:

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

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

#3


1  

It doesn't work that way. Try this

它不起作用。试试这个

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


3  

Use:

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 ;  }

#2


1  

Simply use:

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

Or, if necessary, select only the first-level descendants, the 'immediate' children:

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

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

#3


1  

It doesn't work that way. Try this

它不起作用。试试这个

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 ;  }