【问题标题】:Create a teardrop like css shape without rotation and with an image as background创建一个类似 css 形状的泪珠,无需旋转,并以图像为背景
【发布时间】:2021-02-08 12:47:15
【问题描述】:

我想创建一个这样的 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 形状吗?

谢谢!

【问题讨论】:

  • 我认为我们应该假设在 Paint 中翻转图像在这里不是一个选项:)

标签: html css css-shapes


【解决方案1】:

您可以使用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>

【讨论】:

  • 谢谢!有没有办法让图像覆盖整个空间。我尝试过使用宽度、高度和背景大小,但它看起来不是很好,如果我的图片可能每周更改一次,那么手动调整它们将非常困难。
  • 如果容器总是 180px 那么我的编辑应该可以工作。另一种选择是将源图像旋转 -45 度,这样您就不必使用任何 CSS。我猜因为图像经常变化,这是不可行的?
  • 我添加了另一种方法,您可以使用 clip-path
猜你喜欢
  • 1970-01-01
  • 2018-10-14
  • 2015-08-23
  • 1970-01-01
  • 2015-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-24
相关资源
最近更新 更多