css - 带有渐变叠加和背景图像的 SVG 圆 Angular 三 Angular 形

标签 css image svg mask clip-path

我有以下代码创建一个带有紫色渐变的简单圆 Angular 三 Angular 形。我正在尝试插入一个背景图像来填充渐变下方的形状,以创建与下面的屏幕截图类似的效果:

我要实现的目标:

enter image description here

到目前为止我的代码(不显示图像):

 <svg width="100%" viewBox="0 0 1440 742" version="1.1"
      baseProfile="full"
      xmlns="http://www.w3.org/2000/svg"
      xmlns:xlink="http://www.w3.org/1999/xlink"
      xmlns:ev="http://www.w3.org/2001/xml-events">
     <defs>
         <linearGradient x1="100%" y1="50%" x2="0%" y2="50%" id="linearGradient-1">
             <stop stop-color="#6300FF" stop-opacity="0.7" offset="0%"></stop>
             <stop stop-color="#251D4B" offset="100%"></stop>
         </linearGradient>
         <pattern id="img1" patternUnits="userSpaceOnUse" width="1400" height="742">
             <image xlink:href="https://upload.wikimedia.org/wikipedia/commons/1/11/Varkala_Beach_High_Res.jpg" x="0" y="0" width="1400" height="742" />
         </pattern>
         <path d="M526.611472,1330.75724 C526.681681,1330.68703 525.998884,-525.688822 526.611472,-525.076039 L1243.10385,191.419563 C1359.86286,308.179101 1359.86286,497.502097 1243.10385,614.261635 L526.611472,1330.75724 Z" id="path-2"></path>
     </defs>
     <g id="Desktop" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
         <g id="Knowledge-base-article">
             <g id="businessman-in-workplace-PYDTUKV" transform="translate(-209.000000, -63.000000)">
                 <mask id="mask-3" fill="white">
                     <use xlink:href="#path-2"></use>
                     <use xlink:href="#img1"></use>
                 </mask>
                 <use id="Mask" fill="url(#linearGradient-1)" transform="translate(928.513633, 402.840523) scale(-1, 1) rotate(90.000000) translate(-928.513633, -402.840523) " xlink:href="#path-2"></use>
             </g>
         </g>
     </g>
 </svg>

最佳答案

我会使用如下所示的一些转换来使用纯 CSS 解决方案

.container {
  width:300px;
  height:300px;
  margin:auto;
  position:relative;
  overflow:hidden;
}
.container > div {
  position:absolute;
  width:100%;
  height:100%;
  border-radius:80px;
  transform-origin:top left;
  transform:translateX(-20%) rotate(-45deg);
  overflow:hidden;
}
.container > div:before {
   content:"";
   position:absolute;
   width:calc(100% * 1.4);
   height:calc(100% * 1.4);
   transform:rotate(45deg);
  transform-origin:top left;
   background:
    linear-gradient(to top,rgba(99, 0, 255, 0.7),#251D4B),
    url(https://picsum.photos/300/300?image=1069) top/cover;
}
<div class="container">
  <div></div>
</div>

容器全宽:

.container {
  margin:auto;
  position:relative;
  overflow:hidden;
}
.container > div {
  width:100%;
  padding-top:100%;
  border-radius:15%;
  transform-origin:top left;
  transform:translateY(-15%) translateX(-21%) rotate(-45deg);
  overflow:hidden;
}
.container > div:before {
   content:"";
   position:absolute;
   top:0;
   left:0;
   width:calc(100% * 1.4);
   height:calc(100% * 1.4);
   transform:rotate(45deg);
   transform-origin:top left;
   background:
    linear-gradient(to top,rgba(99, 0, 255, 0.7),#251D4B),
    url(https://picsum.photos/300/300?image=1069) top/cover;
}
<div class="container">
  <div></div>
</div>

关于css - 带有渐变叠加和背景图像的 SVG 圆 Angular 三 Angular 形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54482351/

相关文章:

css - 复制简单图像/文本布局的 css 和/或 javascript

ios - 禁用的自定义 UIButton 在不同的地方显示不同的图像

javascript - 在整个 svg 上缩放内容

javascript - 将 CSS 弹跳动画添加到 div,仅单击一次

Internet Explorer 7 和 8 上的 xhtml 代码的 css 问题

jQuery css() 在 if 语句中不起作用

javascript - SVG 在动画时和完成动画后不显示中心

javascript - 如何操作 svg 外来对象 html 文本换行和定位?

php - CSS/PHP : how to solve this div float problem/odd even loop in array

image - ASIFT 和 SIFT 的替代解决方案?