图像上的CSS透明形状

标签 css html 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>

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

最佳答案

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

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透明形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42816362/

相关文章:

html - CSS - 圆形背景

javascript - 在 CSS 网格中选择列

css - 我如何在我的用户样式表中选择跨域链接?

javascript - 无法将文本访问到 td

html - 非矩形(五边形或六边形)内的文本

html - 如何创建带有图标和边框的响应式菱形 div?

html - 如何制作 3x2 网格?

css - 水平溢出必须从右侧元素开始 AMP 仅 CSS

html - 如何给表格中的每个单元格加边框?

Javascript 多个圆形图