我有一个情景需要编写内联CSS代码,我想在锚点上应用悬停样式。
如何在HTML的style属性中使用a:hover
实现?
例如,在HTML电子邮件中无法可靠地使用CSS类。
我有一个情景需要编写内联CSS代码,我想在锚点上应用悬停样式。
如何在HTML的style属性中使用a:hover
实现?
例如,在HTML电子邮件中无法可靠地使用CSS类。
您可以使用如下的内联样式表语句:
<style>#T1:hover{color:red}</style><span id=T1>Your Text Here</span>
你只能在外部样式表中使用伪类a:hover
。因此,我建议使用外部样式表。代码如下:
a:hover {color:#FF00FF;} /* Mouse-over link */
你可以通过添加类来实现id,但不要使用内联方式。
<style>.hover_pointer{cursor:pointer;}</style>
<div class="hover_pointer" style="font:bold 12pt Verdana;">Hello World</div>
这只有两行,但是你可以在任何地方重新使用这个类。
我的问题是我正在构建一个网站,其中使用了许多图像图标,必须通过悬停在不同的图像上进行替换(例如,蓝色图像在悬停时变为红色)。 我为此提供了以下解决方案:
.container div {
width: 100px;
height: 100px;
background-size: 100px 100px;
}
.container:hover .withoutHover {
display: none;
}
.container .withHover {
display: none;
}
.container:hover .withHover {
display: block;
}
<p>Hover the image to see it switch with the other. Note that I deliberately used inline CSS because I decided it was the easiest and clearest solution for my problem that uses more of these image pairs (with different URL's).
</p>
<div class=container>
<div class=withHover style="background-image: url('https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcQrqRsWFJ3492s0t0NmPEcpTQYTqNnH188R606cLOHm8H2pUGlH')"></div>
<div class=withoutHover style="background-image: url('http://i.telegraph.co.uk/multimedia/archive/03523/Cat-Photo-Bombs-fa_3523609b.jpg')"></div>
</div>