html - 形状渐变

标签 html css gradient linear-gradients

我想在按钮上做一个渐变,但我不能让它与按钮的其他部分具有相同的渐变。 我尝试在渐变内添加渐变,但它似乎不起作用,也找不到解决方案。 这是我正在使用的代码:

button{
  color: white;
  padding: 3px 3px 3px 0px;
  border: 0px;
  font-size: 20px;
  width: 200px;
  text-align: right;
  background: linear-gradient(50deg , transparent 50%, rgb(149, 151, 155) 0%) left no-repeat, linear-gradient(rgb(200, 205, 212), rgb(149, 151, 155)) 30px 0 no-repeat;
  background-size: 30px 100%, 100% 100%;
  position: relative;
  cursor: pointer;
}
<button>Meet the Team</button>

有没有办法解决这个问题? 提前致谢

最佳答案

考虑在应用渐变的伪元素上进行倾斜变换。由于它是顶部/底部方向,因此渐变不会受到倾斜的影响

button{
  color: white;
  padding: 3px 3px 3px 0px;
  border: 0px;
  font-size: 20px;
  width: 200px;
  text-align: right;
  position: relative;
  cursor: pointer;
  overflow:hidden;
  background:none;
  z-index:0;
}
button::before {
  content:"";
  position:absolute;
  z-index:-1;
  top:0;
  left:0;
  right:0;
  bottom:0;
  transform-origin:top;
  transform:skewX(50deg);
  background:linear-gradient(rgb(200, 205, 212), rgb(149, 151, 155));
}
<button>Meet the Team</button>

换个方向,可能需要调整渐变的程度:

button{
  color: white;
  padding: 3px 3px 3px 0px;
  border: 0px;
  font-size: 20px;
  width: 200px;
  text-align: right;
  position: relative;
  cursor: pointer;
  overflow:hidden;
  background:none;
  z-index:0;
}
button::before {
  content:"";
  position:absolute;
  z-index:-1;
  top:0;
  left:0;
  right:0;
  bottom:0;
  transform-origin:top;
  transform:skewX(50deg);
  background:linear-gradient(-50deg,purple,red);
}
<button>Meet the Team</button>

关于html - 形状渐变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59034083/

相关文章:

css - 响应式 Google Maps v3 - 无法获得 100% 的高度

iphone - 如何向 UILabel 的文本添加渐变,而不是背景?

ios - NSGradient drawInBezierPath iOS等效

python - 值错误: ('Series lengths must match to compare' when Using Pandas Style

javascript - 使用这个 jQuery 动画菜单悬停超链接?

html - 如何使用 float 内容使 div 可扩展

CSS:Internet Explorer 中的简单渐变 <= 8

css - 漂浮后的div碰撞

html - 使用css3在悬停上水平滑动图像

jQuery,CSS : Two divs, 如何使它们 "show"彼此相邻?