简体   繁体   English

将锚标记样式也应用于文本和图像

[英]Apply anchor tag style to text as well image

The hover style of color transition and underline is not getting applied to the image. 颜色过渡和下划线的悬停样式不会应用到图像。 It is just applied to the text. 它仅应用于文本。 I understand the color transition requires change in image color but at least underline should happen. 我了解颜色过渡要求更改图像颜色,但至少应出现下划线。

My CSS code is: 我的CSS代码是:

a {
    color: #2b9af3;
    cursor: pointer;
    display: inline-block;
    text-decoration: none;
}
a {
    background-color: transparent;
}
a {
    color: #2b9af3;
    cursor: pointer;
    display: inline-block;
    text-decoration: none;
}
a {
    background-color: transparent;
}

a:hover {
    color: #33ccff;
    text-decoration: underline;
    transition: color 0.4s ease 0s;
}

HTML: HTML:

<a class="hx-back-to-top">Back to top&nbsp;&nbsp; <img src="http://dummyimage.com/7x9/000/fff" class=""></a>

jsfiddle: http://jsfiddle.net/v8rv26dx/1/ jsfiddle: http : //jsfiddle.net/v8rv26dx/1/

just suggestion, why not just put a border bottom when hover the element almost same effect with underline. 只是建议,将元素悬停在具有下划线的效果几乎相同的位置时,为什么不将边框放在底部。

a:hover {
    color: #33ccff;
    border-bottom: 1px solid blue; /* adds border bottom on hover */
    transition: color 0.4s ease 0s;
}


See a sample fiddle here: http://jsfiddle.net/v8rv26dx/3/ 在此处查看样本提琴: http : //jsfiddle.net/v8rv26dx/3/

One solution is to apply the image in CSS as a background for the anchor <a> element, or as the background of a nested <span> . 一种解决方案是将CSS中的图像用作锚点<a>元素的背景或嵌套的<span>的背景。

Alternatively consider applying a bottom border, instead of underlining the text. 或者,考虑使用底部边框,而不是在文本下划线。 See the answer just posted by Alex Newbie. 请参阅Alex Newbie刚刚发布的答案。

try this 尝试这个

a.hx-back-to-top:hover {
    color: #33ccff;
    border-bottom: 1px solid #33ccff; 
    transition: color 0.4s ease 0s;
}

underline added to image also 下划线也添加到图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM