css透明形状在图像上

时间:2017-03-15 17:08:23

标签: html css html5 css-shapes

This is what i am trying to achive

我有:



    #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>
&#13;
&#13;
&#13;

最后,我不知道如何使其旋转并且边缘切割如图所示

3 个答案:

答案 0 :(得分:3)

这方面的一个简单例子是使用伪元素并在背景中设置图像。

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>

答案 1 :(得分:3)

您可以使用伪元素代替嵌套元素。它位于容器div的底部。为此,您需要在容器div上使用position:relativeoverflow:hidden。此外,伪元素始终需要content声明。

要修改边框半径,只需使用伪元素的left | width | height即可。你不需要任何轮换。

您可以使用“新”颜色空间rgba(r,g,b,a)代替十六进制颜色和不透明度,其中a是不透明度值。

对于passepartout,您只需使用border声明。

#image2{
    position:relative;
    border:10px solid #888;
    overflow:hidden;
    box-shadow:0 0 4px #aaa;
}

#image2::after {
    content:"";
    display:block;
    position: absolute;
    bottom: 0;left:-10%;
    background-color: #dc022e;
    width: 120%;
    height: 60%;
    border-radius: 100% 100% 0 0;
    opacity: 0.8;
}
    
#image2 img {
    width: 100%;
    display:block;
    position:relative;
}
<div id="image2">
    <img src="http://t1.gstatic.com/images?q=tbn:ANd9GcThtVuIQ7CBYssbdwtzZjVLI_uw09SeLmyrxaRQEngnQAked5ZB">
  </div>

答案 2 :(得分:1)

您可以使用if event.key == pygame.K_UP: func() 作为图片,position: absolute作为叠加层,根据需要调整顶部位置和宽度。这是一个Fiddle。希望这有帮助!

编辑:这是Fiddle的updated version,展示了img容器上的边框和溢出属性。正如CBroe所说,在这种情况下,旋转一个圆圈可能不是很好地利用你的时间。此外,我绝对同意使用伪元素比嵌套图像更清晰。

相关问题