当li是超链接时,如何删除文本修饰

时间:2014-05-09 02:15:55

标签: css list hyperlink

这是CSS

.ulLink{
text-decoration: none;      
color: grey;
}

这是html

<ul id="myResources">
   <a class="ulLink" href="http://www.acterra.org/greenteams/bottledwater.html"> <li>http://www.acterra.org/greenteams/bottledwater.html</li></a>
   <a class="ulLink" href="http://www.ewg.org/research/chlorine-pollutants-high-levels-dc-  tap-water"><li>http://www.ewg.org/research/chlorine-pollutants-high-levels-dc-tap- water</li></a>
   <a class="ulLink" href="http://www.statisticbrain.com/attention-span-statistics/">   <li>http://www.statisticbrain.com/attention-span-statistics/</li></a>
</ul>

尝试使用ul中的id然后将那个仍然工作。

#myResources {
    text-decoration: none
}

2 个答案:

答案 0 :(得分:3)

您的HTML无效; <li>必须是列表的直接后代。修复它们,你的CSS应该可以工作。

<ul id="myResources">
   <li><a class="ulLink" href="http://www.acterra.org/greenteams/bottledwater.html"> http://www.acterra.org/greenteams/bottledwater.html</a></li>
   <li><a class="ulLink" href="http://www.ewg.org/research/chlorine-pollutants-high-levels-dc-  tap-water">http://www.ewg.org/research/chlorine-pollutants-high-levels-dc-tap- water</a></li>
   <li><a class="ulLink" href="http://www.statisticbrain.com/attention-span-statistics/">   http://www.statisticbrain.com/attention-span-statistics/</a></li>
</ul>

删除dc-tap-water之间的空格也不会造成伤害。

答案 1 :(得分:1)

请勿在{{1​​}}

之前添加a链接
li

使用上面<ul id="myResources"> <li><a class="ulLink" href="http://www.acterra.org/greenteams/bottledwater.html"> http://www.acterra.org/greenteams/bottledwater.html</a></li> <li><a class="ulLink" href="http://www.ewg.org/research/chlorine-pollutants-high-levels-dc-tap-water">http://www.ewg.org/research/chlorine-pollutants-high-levels-dc-tap- water</a></li> <li><a class="ulLink" href="http://www.statisticbrain.com/attention-span-statistics/"> http://www.statisticbrain.com/attention-span-statistics/</a></li> </ul>