[英]Image while hovering a link [HTML+CSS]
So I want to be able to have a link which when hovered, display an image.. So far, I only found tutorial to change an image while it's hovered.. 因此,我希望能够有一个链接,该链接在悬停时显示图像。.到目前为止,我只找到了在悬停时更改图像的教程。
How should I do that please ? 我该怎么办? BTW : I'm a total beginner in HTML.. 顺便说一句:我是HTML的初学者。
Thanks ! 谢谢 !
Use adjacent sibling selector and the display
property. 使用相邻的同级选择器和display
属性。
img { display: none; } a:hover + img { display: block; }
<a href='http://example.com'>Hover Here</a> <img src='https://upload.wikimedia.org/wikipedia/en/2/24/Lenna.png' width='200'>
jQuery for life. 终生的jQuery。
$('.link').mouseover(function() { $('.dog').show(); }).mouseleave(function() { $('.dog').hide(); })
@import url('https://fonts.googleapis.com/css?family=Raleway'); .link { height: 40px; width: 200px; border: 1px solid black; text-align: center; border-radius: 5px; margin-bottom: 10px; } a { text-decoration: none; color: black; font-size: 30px; font-family: Raleway; } .dog { background: url('https://i.ytimg.com/vi/opKg3fyqWt4/hqdefault.jpg'); height: 150px; width: 150px; background-size: cover; display: none; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class='link'> <a href='http://www.google.com'>Hover me</a> </div> <div class='dog'> </div>
Indeed there is couple ways to achieve what you want. 实际上,有两种方法可以实现您想要的。 probably if you are a beginner in html and css, the best for you is to use zer00ne snippet. 如果您是html和css的初学者,那么可能最好的选择是使用zer00ne代码段。 Hovever, if you want to dig deeper I also have the following solution for you: 但是,如果您想深入研究,我还为您提供以下解决方案:
You can test it here https://jsbin.com/barixeqigi/17/edit?html,css,js,output 您可以在这里进行测试https://jsbin.com/barixeqigi/17/edit?html,css,js,output
HTML 的HTML
<a href="#" title="super eye" alt="super eye">
hover
</a>
CSS 的CSS
a {
position:relative;
}
a:after {
content:'';
display:block;
width: 200px;
height: 200px;
opacity:0;
background: url('http://cdn.arstechnica.net/wp-content/uploads/2016/02/5718897981_10faa45ac3_b-640x624.jpg') no-repeat center;
background-size: cover;
border-radius:50%;
position:absolute:
right:0px;
top:0px;
-webkit-transition: all 3s;
transition: all 3s;
}
a:hover:after {
opacity: 100;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.