css 图像上的透明形状

css transparent shape over image

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>

最后我不知道如何让它像图片那样旋转和切掉边距

您可以只对图像使用 position: absolute,对叠加层使用 position: relative,根据需要调整顶部位置和宽度。这是 Fiddle。希望这对您有所帮助!

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

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

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>

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

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

除了十六进制颜色和不透明度,您还可以使用 "new" 颜色 space rgba(r,g,b,a),其中 a 是不透明度值。

对于路路通,您只需使用 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>