我需要一个简单的按钮与 colored颜色 渐变和一个透明的渐变叠加伪装灯光眩光.在过go ,我只创建了 colored颜色 渐变(red to dark red)的按钮,并在按钮上设置了一个透明渐变(white, with opacity 0.25 to 0.50)的层.

Like this Button:
concave rectangle with transparent gradient


But I have big problem with a concave horizon line:
concave rectangle with transparent gradient


我在这里标了一条理论上的线,只是为了更好地理解.


Tryout code on fiddle:
I've been experimenting a bit with concave background settings here. But then I get no transparent history.

#wrapper {
  background: grey;
  padding: 25px;
}

#test {
    display: inline-block;
    width: 200px;
    height: 200px;
    margin-right: 25px;
    border-radius: 20px;
    background: #888888;
    background:
      radial-gradient(circle 400px at 50% 266%, rgba(0,0,250,0.1), rgba(0,0,250,0.1) 100%, red 100%);
    background-size:200px 200px, 200px 200px;
    background-position:0 0,0 0;
    background-repeat:no-repeat;
}
<div id="wrapper">
  <div id="test">B1</div>
  <div id="test">B2</div>
</div>

但我的CSS2技能完全过时了. 因此,我的财务按钮是否有更好的解决方案就成了问题.

有人知道如何创建这样一个按钮(like the red one in the first picture)吗?现在可能会有更现代、更简单的解决方案.-重要的是,地平线是concave (laterally downwards),而不是凸(ellipse downwards in the middle).完全如图所示.

为了提高我的技能,我必须与更多的css-3和最新技术打交道.

推荐答案

可以叠加多个渐变,一个叠加在另一个之上.我使用了一个透明的圆形径向渐变来淡出带有边缘的按钮,然后在它下面放置一个线性渐变.然后,您可以使用CSS自定义属性将按钮 colored颜色 设置为您喜欢的任何 colored颜色 .代码如下.调整rgba()属性中的不透明度值以获得您想要的效果.

Edited由于半径不能是百分比值,所以我使用了一个自定义属性,以便按钮半径随按钮大小进行zoom ,这样您就可以使用不同宽度的按钮,并且可以很好地扩展.

#wrapper {
  background: grey;
  padding: 25px;
}

.button {
    display: inline-grid;
    place-items:center;
    --width:200px;
    width: var(--width);
    aspect-ratio:1/1;
    margin-right: 25px;
    border-radius: 20px;
    --button-colour: blue;
    background:
      radial-gradient(
        circle calc(var(--width) * 4) at 50% 270%,
        transparent 50%,
        rgba(255,255,255,0.2) 50%,
        rgba(255,255,255,1) 75%),
      linear-gradient(
        var(--button-colour),
        var(--button-colour)
      );
}

.red {
  --button-colour:red;
}

.green {
  --button-colour:green;
}

.blue {
  --button-colour:blue;
}

.small {
 --width:100px;
}
<div id="wrapper">
  <div class='red button'>Red</div>
  <div class='green button'>Green</div>
  <div class='blue button'>Blue</div>
  <div class='small blue button'>Blue</div>
</div>

Html相关问答推荐

为什么html复选框总是具有只读属性?

我需要主页按钮出现在中间

当表头包含特殊字符时,R Quarto发布的HTML表中不必要的大列宽

CSS自定义特性中的URL是否可以相对于定义的CSS文件?

有没有办法根据另一个项目调整FlexBox项目的大小?

我无法从带Angular 的Bootstrap 5中的表单中获取数据

当文本添加到元素中时,将元素拉到页面上

使用CSS Flexbox时,我的图像未对齐

为什么当我按第三个按钮时,前两个按钮会跳动?

为什么溢出时overflow: auto框的底部有一个小间隙?

文本不显示在 div 下方

在 iPhone 上分隔 HTML 邮箱输入中的多个邮箱条目

在shiny 的应用程序中使用图标功能时出错

标签背景 colored颜色 的 html 和 css 技巧说明

单击按钮时更改字体真棒图标

如何在没有容器的情况下沿基线将 div 中的元素居中?

当我将鼠标悬停在测试类上时,左侧类的 colored颜色 没有改变

将 div 放在图片旁边而不是下方

如何自定义具有白色透明背景的光标图像?

标题之间和之后的 Hr 线