В случае, если градиент всегда будет сверху вниз (или снизу вверх), вы можете рассмотреть некоторые хитрости, используя перекос, как показано ниже.Идея состоит в том, чтобы использовать псевдоэлементы, где вы применяете два разных градиента, которые будут пересекаться в одном цвете, создавая иллюзию одного градиента.
.box {
width: 150px;
padding: 20px;
box-sizing: border-box;
position: relative;
color: #fff;
z-index: 0;
overflow: hidden;
margin:5px;
border-radius:5px 0 0 5px;
}
.box:before,
.box:after {
content: "";
position: absolute;
z-index:-1;
height: 50%;
left: 0;
right: 0;
}
.box:before {
top: 0;
background: linear-gradient(to bottom, blue, #4100bf);
transform: skewX(30deg);
transform-origin: bottom right;
}
.box:after {
bottom: 0;
background: linear-gradient(to top, purple, #4100bf);
transform: skewX(-30deg);
transform-origin: top right;
}
<div class="box">
Some text here
</div>
<div class="box">
Some text here Some text here
</div>
Другая идея без прозрачности состоит в том, чтобы рассмотреть многократный фон и скрыть градиент белым цветом (или любым цветом фона).Затем вы можете рассмотреть любой вид градиента, даже радиальный градиент.
.box {
width: 150px;
padding: 20px;
box-sizing: border-box;
color: #fff;
margin:5px;
background:
linear-gradient(to bottom right,transparent 48%,#fff 50%) bottom right/20px 50%,
linear-gradient(to top right,transparent 48%,#fff 50%) top right/20px 50%,
linear-gradient(to bottom, blue,purple);
background-repeat:no-repeat;
border-radius:5px 0 0 5px;
}
<div class="box">
Some text here
</div>
<div class="box">
Some text here Some text here
</div>
У вас также есть решение для пути обрезки:
.box {
width: 150px;
padding: 20px;
box-sizing: border-box;
color: #fff;
margin: 5px;
background: linear-gradient(to bottom, blue, purple);
background-repeat: no-repeat;
border-radius: 5px 0 0 5px;
-webkit-clip-path: polygon(0% 0%, calc(100% - 20px) 0%, 100% 50%, calc(100% - 20px) 100%, 0% 100%);
clip-path: polygon(0% 0%, calc(100% - 20px) 0%, 100% 50%, calc(100% - 20px) 100%, 0% 100%);
}
<div class="box">
Some text here
</div>
<div class="box">
Some text here Some text here
</div>