英文:
How to get a gradient border on two half sides of a image, as shown in attached image
问题
我的代码:
<!-- 开始代码片段:js 隐藏:false 控制台:true Babel:false -->
<!-- 语言:lang-css -->
body {
  height: 100vh;
  margin: 0;
  display: grid;
  place-items: center;
  background: #000000;
}
.module-border-wrap {
  max-width: 320px;
  padding: 1rem;
  position: relative;
  background: linear-gradient(130deg, rgba(248,253,254,1) 50%, rgba(33,186,227,1) 100%);
  padding: 6px;
  border-radius: 1.5rem 1.5rem 0 1.5rem;
}
.module {
  background: #ffffff;
  color: #000000;
  padding: 2rem;
  border-radius: 1.5rem 1.5rem 0 1.5rem;
}
.w-100{
  width:100;
}
.p-0{
  padding:0;
}
.relative{
  position: relative;
}
.curved{
  border-radius: 30px 30px 0 30px;
}
<!-- 语言:lang-html -->
<div class="module-border-wrap">
   <div class="module p-0 relative curved">
      <img src="https://picsum.photos/300/200" class="w-100 curved" alt="">
   </div>
</div>
<!-- 结束代码片段 -->
到目前为止,我能够获得渐变效果,但是它显示在图像的外面,不像附带的屏幕截图中那样,渐变边框在图像上方。
<details>
<summary>英文:</summary>
My code:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
     body {
      height: 100vh;
      margin: 0;
      display: grid;
      place-items: center;
      background: #000000;
    }
    .module-border-wrap {
      max-width: 320px;
      padding: 1rem;
      position: relative;
      background: linear-gradient(130deg, rgba(248,253,254,1) 50%, rgba(33,186,227,1) 100%);
      padding: 6px;
      border-radius: 1.5rem 1.5rem 0 1.5rem;
    }
    .module {
      background: #ffffff;
      color: #000000;
      padding: 2rem;
      border-radius: 1.5rem 1.5rem 0 1.5rem;
    }
    .w-100{
      width:100;
    }
    .p-0{
      padding:0;
    }
    .relative{
      position: relative;
    }
    .curved{
      border-radius: 30px 30px 0 30px;
    }
<!-- language: lang-html -->
    <div class="module-border-wrap">
       <div class="module p-0 relative curved">
          <img src="https://picsum.photos/300/200" class="w-100 curved" alt="">
       </div>
    </div>
<!-- end snippet -->
So far, I am able to get the gradient, however, its showing outside of image, unlike in the attached screenshot, where the gradient border is over the image itself.
[jsfiddle][1]
[![enter image description here][2]][2]
  [1]: https://jsfiddle.net/0hL213uv/20/
  [2]: https://i.stack.imgur.com/RAZMq.png
</details>
# 答案1
**得分**: 3
你可以尝试使用一个伪元素和多个背景。
<details>
<summary>英文:</summary>
You can try using one pseudo element and multiple backgrounds
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
    body {
      height: 100vh;
      margin: 0;
      display: grid;
      place-items: center;
      background: #000000;
    }
    .box {
      border-radius: 1.5rem 1.5rem 0 1.5rem;
      overflow: hidden;
      display: flex;
      position: relative;
    }
    .box:before {
      content:"";
      position:absolute;
      inset: 0;
      --g: #0000 1.8rem,#21bae3; /* update the color here */
      --t: 10px; /* the thickness of the gradient */
      background:
       linear-gradient( 90deg,var(--g)) bottom/100% var(--t),
       linear-gradient(180deg,var(--g)) right /var(--t) 100%;
      background-repeat: no-repeat;
    }
<!-- language: lang-html -->
    <div class="box">
      <img src="https://picsum.photos/300/200"  >
    </div>
<!-- end snippet -->
</details>
				通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。



评论