我正在添加图像链接,但无法删除为文本链接指定的a:link样式和a:hover样式。
我为a.button:link和a.button:hover添加了新的.css样式,
#content a.button:link {
text-decoration:none;
}
#content a.button:hover {
text-decoration:none;
}
并设置
<a href="www.website.com" class="button"><img></img></a>
但是它仍然使用默认样式!我快要疯了。我检查了不同的网站,他们都说要在href后面简单地使用class =“ nameofclass”,但是使用图像时,在我的网站上它对我不起作用。
根据要求的JSFiddle:https ://jsfiddle.net/aqtq2gq4/1/
定位标记的“自然”行为仅仅是包含文本的链接,对不对?因此,当您为img添加此锚标记时,您看到的矩形是浏览器为文本“准备”的,因此它的高度为默认字体大小。
诀窍是使.button类的字体大小为0px,删除填充,并删除边框,然后瞧!
#content a.button:link {
text-decoration:none;
font-size: 0px;
padding: 0px;
border: none;
}
#content a.button:hover {
text-decoration:none;
font-size: 0px;
padding: 0px;
border: none;
}
这会将不透明度添加到img中:
#content a.button > img:hover{
opacity: 0.8;
}
希望这就是您想要的!
这是更新的小提琴。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句