Html 如何在CSS中选择文本而不是图像

Html 如何在CSS中选择文本而不是图像,html,css,css-selectors,Html,Css,Css Selectors,简单问题:我有以下标记 <a href='#'> <img src='icon.png'> This is the link </a> 我想让文本在鼠标上方加下划线 什么是CSS选择器,用于仅选择元素中的文本而不选择其他内容?如果不需要的话,我宁愿不把它包起来 a:hover { text-decoration: none; } a:hover <select_text_here> { text-decoration: under

简单问题:我有以下标记

<a href='#'>
  <img src='icon.png'> This is the link
</a>

我想让文本在鼠标上方加下划线

什么是CSS选择器,用于仅选择
元素中的文本而不选择其他内容?如果不需要的话,我宁愿不把它包起来

a:hover {
  text-decoration: none;
}
a:hover <select_text_here> {
  text-decoration: underline;
}
a:悬停{
文字装饰:无;
}
a:悬停{
文字装饰:下划线;
}

我看到Opera/IE没有在图像下面画线,但FF画线。最简单的修复方法是添加
span
元素:

<a href="..."><img ... /> <span>...</span></a>
a:hover span {
  text-decoration: underline;
}

据我所知,您不能只选择文本。

我看到Opera/IE没有在图像下划线,但FF可以。最简单的修复方法是添加
span
元素:

<a href="..."><img ... /> <span>...</span></a>
a:hover span {
  text-decoration: underline;
}

据我所知,您无法仅选择文本。

文本必须位于其自身的元素中,才能在CSS中进行选择。您必须使用
span
或类似工具:

<a href="#"><img src="" /><span class="link-text">Foo</span></a>


显然,您可以使用
.linktext
来选择它。

文本必须在其自己的元素中才能在CSS中选择。您必须使用
span
或类似工具:

<a href="#"><img src="" /><span class="link-text">Foo</span></a>


显然,您可以使用
.link text
来选择它。

由于文本没有任何单独的“句柄”可供选择,因此您最好在整个
标记下加下划线,该标记包括图像。图像本身在技术上不会加下划线,因此您甚至不能“取消加下划线”


您必须将图像与文本分开,或者将文本包装在
span
中并仅突出显示该文本。

由于文本没有任何单独的“句柄”可供选择,因此您最好在整个
标记下加下划线,该标记包括图像。图像本身在技术上不会加下划线,因此您甚至不能“取消加下划线”

您必须将图像与文本分开,或者将文本包装成一个
span
,并仅突出显示该文本。

或许可以尝试以下方法:

a:hover {
  text-decoration: underline;
}
a:hover IMG {
  text-decoration: none;
}
也许可以试试这个:

a:hover {
  text-decoration: underline;
}
a:hover IMG {
  text-decoration: none;
}
你可以做的另一件事是

a{
    background: url(icon.png); background-repeat: no-repeat; padding-left: 10px
}
或者类似的,所以链接中不必有image元素

a:hover {
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

a img{
   text-decoration: none;
}
你可以做的另一件事是

a{
    background: url(icon.png); background-repeat: no-repeat; padding-left: 10px
}
或者类似的,所以链接中不必有image元素

a:hover {
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

a img{
   text-decoration: none;
}
我应该这样做。这样,a中的所有img标记将没有任何下划线


我应该这样做。这样,a中的所有img标签都将没有任何下划线。

好的,这就是我要找的。我将把它用
包装起来。我想CSS可能有一些特别的选择器我不知道。谢谢好吧,这就是我要找的。我将把它用
包装起来。我想CSS可能有一些特别的选择器我不知道。谢谢