微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

创建像css形状一样的泪珠,不旋转并且以图像为背景

如何解决创建像css形状一样的泪珠,不旋转并且以图像为背景

我想创建一个这样的CSS形状(我不知道该形状的名称),并为其添加背景图像。你们可以帮我吗?

形状是:

.figure{
    width: 180px;
    height: 180px;
    border: 1px solid #32557f;
    border-radius: 0 50% 0% 50%;
    transform: rotate(45deg);
    bottom: -50px;
    position: relative;
    left: 17px
  }
<div class="figure"></div>

如果我附加背景图像,它也会受到旋转的影响。

.figure{
    width: 180px;
    height: 180px;
    border: 1px solid #32557f;
    border-radius: 0 50% 0% 50%;
    transform: rotate(45deg);
    background-size: 100%;
    background-image:url('https://images.unsplash.com/photo-1593642634315-48f5414c3ad9');
    background-repeat:no-repeat;
    bottom: -50px;
    position: relative;
    left: 17px
  }
<div class="figure"></div>

好,我当前的解决方案如下:

  .figure {
    width: 180px;
    height: 180px;
    border: 1px solid #32557f;
    border-radius: 0 50% 0% 50%;
    transform: rotate(45deg);
    bottom: -50px;
    position: relative;
    left: 17px;
    overflow: hidden;
  }
  

  .test{
    background-image: url(https://images.unsplash.com/photo-1602000750546-f8e331a082d1);
    transform: rotate(-45deg);
    height: 145%;
    width: 142%;
    background-size: cover;
    background-repeat: no-repeat;
    background-size: 100%;
    position: fixed;
    top: -43px;
    right: -44px;
  }
<div class="figure">
    <div class="test"></div>
</div>

有人知道如何称呼此CSS形状吗?

谢谢!

解决方法

您可以使用img代替background-image,并使用transform: rotate(-45deg)抵消旋转:

.figure {
  width: 180px;
  height: 180px;
  border: 1px solid #32557f;
  border-radius: 0 50% 0% 50%;
  transform: rotate(45deg);
  bottom: -50px;
  position: relative;
  left: 17px;
  overflow: hidden;
}

img {
  height: 142%;
  transform: rotate(-45deg) translateY(-39%);
}
<div class="figure">
  <img src="https://images.unsplash.com/photo-1593642634315-48f5414c3ad9" />
</div>


另一种选择是将clip-pathsvg一起使用:

img {
  height: 260px;
  clip-path: url(#teardrop);
}
<img src="https://images.unsplash.com/photo-1593642634315-48f5414c3ad9" />

<svg>
    <clipPath id="teardrop">
        <path
            d="M88.49 0C121.05 32.57 141.41 52.92 149.55 61.06C186.12 97.63 186.12 156.93 149.55 193.5C141.41 201.64 121.05 221.99 88.49 254.56C55.92 221.99 35.57 201.64 27.43 193.5C-9.14 156.93 -9.14 97.63 27.43 61.06C35.57 52.92 55.92 32.57 88.49 0Z"
        ></path>
    </clipPath>
</svg>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。