html – css透明形状覆盖图像

前端之家收集整理的这篇文章主要介绍了html – css透明形状覆盖图像前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
This is what i am trying to achive

我有 :

  1. #image1 {
  2. position: absolute;
  3. bottom: 0px;
  4. align-self: auto;
  5. background-color: #dc022e;
  6. width: 340px;
  7. height: 100px;
  8. border-radius: 50% / 100%;
  9. border-bottom-left-radius: 0;
  10. /*transform: rotate(10deg);*/
  11. border-bottom-right-radius: 0;
  12. opacity: 0.8;
  13. }
  14. #image2 img {
  15. width: 80%;
  16. }
  1. <div>
  2. <div id="image2">
  3. <img src="http://t1.gstatic.com/images?q=tbn:ANd9GcThtVuIQ7CBYssbdwtzZjVLI_uw09SeLmyrxaRQEngnQAked5ZB">
  4. </div>
  5. <div id="image1"></div>
  6. </div>

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

解决方法

一个简单的例子是使用伪元素并在背景中设置图像.
  1. div {
  2. position: relative;
  3. height: 300px;
  4. width: 500px;
  5. background: url(http://lorempixel.com/500/300);/*image path*/
  6. overflow: hidden;/*hides the rest of the circle*/
  7. }
  8.  
  9. div:before {
  10. content: "";
  11. position: absolute; /*positions with reference to div*/
  12. top: 100%;
  13. left: 50%;
  14. width: 0;/*define value if you didn't want hover*/
  15. height: 0;
  16. border-radius: 50%;
  17. background: tomato;/*could be rgba value (you can remove opacity then)*/
  18. opacity: 0.5;
  19. transform: translate(-50%,-50%);/*ensures it is in center of image*/
  20. transition: all 0.4s;
  21. }
  22.  
  23.  
  24. /*Demo Only*/
  25. div:hover:before {/*place this in your pseudo declaration to remove the hover*/
  26. height: 100%;
  27. width: 150%;/*this makes the shape wider than square*/
  28. transform: translate(-50%,-50%) rotate(5deg);/*ensures it is in center of image + rotates*/
  29. }
  30. div {/*This stuff is for the text*/
  31. font-size: 40px;
  32. line-height: 300px;
  33. text-align: center;
  34. }
  1. <div>HOVER ME</div>

猜你在找的HTML相关文章