gpt4 book ai didi

css - 响应式两个渐变对 Angular 线按钮

转载 作者:行者123 更新时间:2023-11-28 14:36:20 24 4
gpt4 key购买 nike

我有一个按对 Angular 线分割的按钮。我想在每一侧添加不同的渐变。我试过使用 :before 和 :after 分成两部分,但这需要旋转或倾斜,这意味着改变不是很灵敏的度数。基本上,无论宽度和高度如何,我都需要在中心切断以在不同的断点处保持左上角和右下角。有更好的方法吗?

.btn {
background-image: linear-gradient(47deg, #f09 0%, #A09 100%);
display: inline-block;
font-size: 1.6rem;
text-decoration: none;
text-align: center;
cursor: pointer;
max-width: 32rem;
width: 100%;
padding: 2.6rem 1rem;
color: $white;
text-transform: uppercase;
vertical-align: middle;
overflow: hidden;
position: relative;
z-index: 1;
}

.btn:after {
content: '';
width: 100%;
left: 0%;
right: 0;
bottom: 0;
top: 48%;
background-image: linear-gradient(47deg, #A09 0%, #f09 100%);
position: absolute;
transform: skewY(14deg);
height: 200%;
z-index: -1;
}
<a href="" class="btn">Button</a>

最佳答案

您可以在按钮内保留一个渐变,然后考虑在伪元素上使用 clip-path 来创建三 Angular 形并应用第二个渐变:

.btn {
background-image: linear-gradient(to right, yellow,blue);
display: inline-block;
font-size: 1.6rem;
text-decoration: none;
padding: 2.6rem 1rem;
color: #fff;
text-transform: uppercase;
position: relative;
z-index: 0;
}

.btn:after {
content: '';
position:absolute;
left: 0;
right: 0;
bottom: 0;
top: 0;
background-image: linear-gradient(to left, yellow,blue);
-webkit-clip-path:polygon(0 0,100% 0,100% 100%);
clip-path:polygon(0 0,100% 0,100% 100%);
z-index: -1;
}
<a href="" class="btn">Button</a>
<a href="" class="btn">Another Button</a>

关于css - 响应式两个渐变对 Angular 线按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53446402/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com