[英]how to do a 50% hover overlay effect for a circular image
I have a functionality in my website that when the user hovers on his/her display picture an overlay will appear.我的网站中有一个功能,当用户将鼠标悬停在他/她的显示图片上时,会出现一个叠加层。
But sadly I want the overlay not to cover up the entire photo.但遗憾的是,我希望覆盖层不要覆盖整张照片。 I want it to be just half of the circle.我希望它只是圆的一半。
I have tried researching for solutions but I can't seem to find any solution to this.我曾尝试研究解决方案,但似乎找不到任何解决方案。
Here is an image of how I want it to look like.这是我希望它看起来像的图像。
thanks in advance.提前致谢。
And i would really appreciate it if you would guide me on how to achieve this effect.如果您能指导我如何实现这种效果,我将不胜感激。
The trick is, to add overflow:hidden
to the container (circle) and make the overlay half the height of the circle.诀窍是,将overflow:hidden
添加到容器(圆)并使覆盖层的高度为圆的一半。 Here is an example code:这是一个示例代码:
#circle{ width:200px; height:200px; border-radius:50%; background-color:#0098dd; position:relative; overflow:hidden; } #overlay{ display:none; position:absolute; bottom:0; text-align:center; width:200px; height:100px; /* Half of the container */ line-height:100px; background-color:rgba(255,255,255,0.5); } #circle:hover #overlay{ display:block; }
<div id="circle"> <div id="overlay"> Test </div> </div>
parent div will have position:relative;
父 div 将具有position:relative;
and overflow:hidden;
和overflow:hidden;
. . the overlay will have position:absolute;
叠加层将具有position:absolute;
with top:50%;
top:50%;
(to cover only the bottom half of the parent). (仅覆盖父级的下半部分)。
To make it appear :让它出现:
First Method : You can set .overlay
to display:none;
第一种方法:您可以将.overlay
设置为display:none;
and .con:hover .overlay
to display:block;
和.con:hover .overlay
到display:block;
Second Method: You can set .overlay
to top:100%; transition:top 0.5s;
第二种方法:您可以将.overlay
设置为top:100%; transition:top 0.5s;
top:100%; transition:top 0.5s;
and .con:hover .overlay
to top:50%;
和.con:hover .overlay
to top:50%;
. . The transition
is added to make the change slow.添加transition
是为了使更改变慢。
Check out the snippet below which uses second method.查看下面使用第二种方法的代码段。 Also I used font-awesome for the icons.我还为图标使用了 font-awesome。
.con{ width:150px; height:150px; border-radius:75px; background-image:url("http://www.chinabuddhismencyclopedia.com/en/images/thumb/b/b8/Nature.jpg/240px-Nature.jpg"); background-size:cover; overflow:hidden; position:relative; } .overlay{ position:absolute; top:100%; left:0; padding-top:10px; text-align:center; width:100%; height:100%; background-color:rgba(255,255,255,0.5); transition:top 0.5s; } .con:hover .overlay{ top:50%; } .overlay a{ margin:5px; font-size:1.6em; }
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/> <div class="con"> <div class="overlay"> <a><i class="fa fa-briefcase"></i></a> <a><i class="fa fa-list"></i></a> </div> </div>
You have to use overflow: hidden;
你必须使用overflow: hidden;
Please check this jsfiddle请检查这个jsfiddle
https://jsfiddle.net/3jdb1m7e/ https://jsfiddle.net/3jdb1m7e/
i hope you like with transition
.我希望你喜欢transition
。
<div class="img-box">
<img src="http://placehold.it/350x350" class="image">
<div class="img-content">
<a href="#"><img src="https://cdn2.iconfinder.com/data/icons/pittogrammi/142/96-128.png" width="36px" height="36px" /></a>
<a href="#"><img src="https://cdn0.iconfinder.com/data/icons/internet-and-web-flat-icons-free/512/Menu_icon-128.png" width="36px" height="36px"/></a>
</div>
</div>
.img-box {
position: relative;
text-align: center;
display: block;
border-radius: 105px;
overflow: hidden;
width: 200px;
height: 200px;
border: 1px solid #333;
}
.img-box .image{
border-radius: 50%;
width: 100%;
}
.img-content {
padding: 40px;
background: #fff;
position: absolute;
bottom: -120px;
width: 100%;
box-sizing: border-box;
transition: all 0.2s ease-in-out;
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
}
.img-box:hover .img-content{
bottom: 0px;
transition: all 0.2s ease-in-out;
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.