CSS: Skip underline in part of link
Pergunta
Is it possible to have a contiguous link, where the text is normally underlined on mouse hover, but in the middle have a section (eg an image) without this underline? This does not work:
<a href="#">one <span style="text-decoration:none;">two</span> <img src="img.png" style="border:0px; text-decoration:none;"> three</a>
Solução 3
What I really wanted was to have an image "attached" to links, without it getting underlined on hover. Here is a solution I came up with:
<a href="#" style="background:url('pic.png') no-repeat; background-position: left center; padding-left: 20px;">Link</a>
- padding-left is for offsetting the text so it does not overlap the image.
- With background-position you can move the image to make it better aligned with the text.
- If the image is higher than the text padding-top and padding-bottom can be used to tweak the appearance.
This technique can also be used with CSS sprites like this:
<a href="#" style="background:url('sprites.png') no-repeat; background-position: -16px -16px; padding-left: 32px;">Link</a>
I used a similar technique to use CSS sprites instead of ordinary inline images:
<span style="background:url('sprites.png') no-repeat; background-position: -16px -16px; padding-left: 32px;"></span>
Hope this helps someone
Outras dicas
a, a:hover { text-decoration: underline; }
a img, a:hover img { text-decoration: none !important; }
<a href="#" style="text-decoration:none;">
<span style="text-decoration:underline;">one</span>
two
<img src="img.png" style="border:0px; text-decoration:none;"> three
</a>
I think it can only be possible using javascript as follows.
LOOK FOLLOWING EXAMPLE
<html>
<head></head>
<style>
a{
text-decoration:none;
}
a:hover
{
text-decoration:none;
}
.sample
{
text-decoration:underline;
}
.sample_none
{
text-decoration:none;
}
</style>
<script type="text/javascript">
function show_underline(){
document.getElementById('sample').className= 'sample';
}
function hide_underline(){
document.getElementById('sample').className= 'sample_none';
}
</script>
<a href="#" onmouseover="show_underline();" onmouseout="hide_underline();"> <span id="sample" class="sample_none">two</span>
<img src="img.png" style="border:0px;"> three
</a>
</body>
</html>
P.S. I would like to know if it is possible with css and html only
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow