如何使用HTML CSS显示附加形状的图像

huangapple go评论69阅读模式
英文:

How to show image as attached shape using html css

问题

以下是您要翻译的内容:

我尝试使用线性渐变但无法在左上角实现边框半径。

英文:

如何使用HTML CSS显示附加形状的图像

I tried to do it using linear-gradient but unable to achieve border radius on top left corner.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.img-container {
    background-image: url(&#39;https://loremflickr.com/680/520/car,forest&#39;);
    background-repeat: no-repeat;
    background-size: cover;
    border-radius: 0px 42px 42px 4px;
    position: relative;
    width: 600px;
    height: 320px;
    background-position: 100%;
}

.img-container::before {
    content: &#39;&#39;;
    position: absolute;
    left: 0;
    top: -4px;
    width: 182px;
    height: calc(100% + 2px);
    background: linear-gradient(to top left, transparent 50%, white 50.1%)
      bottom left / 182px no-repeat transparent;
}

<!-- language: lang-html -->

&lt;div class=&quot;img-container&quot;&gt;&lt;/div&gt;

<!-- end snippet -->

答案1

得分: 1

倾斜变换可以在这里有所帮助:

&lt;!-- 开始代码片段: js 隐藏: false 控制台: true Babel: false --&gt;

&lt;!-- 语言: lang-css --&gt;

    .img-container {
      border-radius: 10px;
      height: 250px;
      width: 400px;
      overflow: hidden;
      transform-origin: bottom;
      transform: skewX(-20deg);
    }

    img {
      display: block;
      width: 100%;
      height: 100%;
      object-fit: cover;
      border-radius: 0px 42px 42px 4px;
      transform-origin: bottom;
      transform: skewX(20deg); /* 反向值在这里 */
    }

&lt;!-- 语言: lang-html --&gt;

    &lt;div class=&quot;img-container&quot;&gt;
      &lt;img src=&quot;https://loremflickr.com/680/520/car,forest&quot;&gt;
    &lt;/div&gt;

&lt;!-- 结束代码片段 --&gt;
英文:

Skew transformation can help here:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.img-container {
  border-radius: 10px;
  height: 250px;
  width: 400px;
  overflow: hidden;
  transform-origin: bottom;
  transform: skewX(-20deg);
}

img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 0px 42px 42px 4px;
  transform-origin: bottom;
  transform: skewX(20deg); /* the opposite value here */
}

<!-- language: lang-html -->

&lt;div class=&quot;img-container&quot;&gt;
  &lt;img src=&quot;https://loremflickr.com/680/520/car,forest&quot;&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年6月27日 21:03:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76565160.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定