css在图像上的透明形状 [英] css transparent shape over image
本文介绍了css在图像上的透明形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有:
#image1 {position :绝对; bottom:0px; align-self:auto; background-color:#dc022e;宽度:340px; height:100px;边界半径:50%/ 100%; border-bottom-left-radius:0; / * transform:rotate(10deg); * / border-bottom-right-radius:0;不透明度:0.8; }#image2 img {width:80%; }
< div> < div id =image2> < img src =http://t1.gstatic.com/images?q=tbn:ANd9GcThtVuIQ7CBYssbdwtzZjVLI_uw09SeLmyrxaRQEngnQAked5ZB> < / DIV> < div id =image1>< / div>< / div>
最后,我不知道如何让它旋转,并像图片一样切割边距。
解决方案
<一个快速的例子就是使用一个伪元素,并在后台设置图片。
div {position:relative; height:300px;宽度:500px;背景:url(http://lorempixel.com/500/300); / *图片路径* / overflow:hidden; / *隐藏圆圈的其余部分* /} div:before {content:;位置:绝对; / *参照div * / top的位置:100%;剩下:50%;宽度:0; / *定义值,如果你不想悬停* / height:0;边界半径:50%;背景:番茄; / *可能是rgba值(你可以去除不透明度)* /不透明度:0.5; transform:translate(-50%,-50%); / *确保它位于图像的中心* / transition:全部为0.4s;} / * Demo Only * / div:hover:before {/ *声明删除悬停* /高度:100%; / *转换:旋转(-50%,-50%)旋转(5deg); / *确保它在图像的中心+旋转* /} div {/ *这是东西的文字* / font-size:40px; line-height:300px; text-align:center;}
< div> HOVER ME< / div>
This is what i am trying to achive
i have :
#image1 {
position: absolute;
bottom: 0px;
align-self: auto;
background-color: #dc022e;
width: 340px;
height: 100px;
border-radius: 50% / 100%;
border-bottom-left-radius: 0;
/*transform: rotate(10deg);*/
border-bottom-right-radius: 0;
opacity: 0.8;
}
#image2 img {
width: 80%;
}
<div>
<div id="image2">
<img src="http://t1.gstatic.com/images?q=tbn:ANd9GcThtVuIQ7CBYssbdwtzZjVLI_uw09SeLmyrxaRQEngnQAked5ZB">
</div>
<div id="image1"></div>
</div>
Finally I don't know how to make it rotated and with the margins cut like in the picture
解决方案
A Quick example of this would use a pseudo element and have the image set in the background.
div {
position: relative;
height: 300px;
width: 500px;
background: url(http://lorempixel.com/500/300);/*image path*/
overflow: hidden;/*hides the rest of the circle*/
}
div:before {
content: "";
position: absolute; /*positions with reference to div*/
top: 100%;
left: 50%;
width: 0;/*define value if you didn't want hover*/
height: 0;
border-radius: 50%;
background: tomato;/*could be rgba value (you can remove opacity then)*/
opacity: 0.5;
transform: translate(-50%, -50%);/*ensures it is in center of image*/
transition: all 0.4s;
}
/*Demo Only*/
div:hover:before {/*place this in your pseudo declaration to remove the hover*/
height: 100%;
width: 150%;/*this makes the shape wider than square*/
transform: translate(-50%, -50%) rotate(5deg);/*ensures it is in center of image + rotates*/
}
div {/*This stuff is for the text*/
font-size: 40px;
line-height: 300px;
text-align: center;
}
<div>HOVER ME</div>
这篇关于css在图像上的透明形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文