英文:
concave rectangle with transparent gradient
问题
我需要一个简单的按钮,带有颜色渐变和一个透明的渐变覆盖层,模拟光芒。在过去,我只创建了带有颜色渐变(从红色到深红色)的按钮,并在按钮上设置了一个带有透明渐变(白色,不透明度为0.25到0.50)的层。
我在这里用一个理论线标记了它,只是为了更好地理解。
在fiddle上尝试的代码:
我在这里尝试了一些凹凸的背景设置。但是我得不到透明的历史记录。
<div id="wrapper">
<div id="test">B1</div>
<div id="test">B2</div>
</div>
但是我的CSS 2技能已经过时了。因此,问题是是否有更好的解决方案来创建我的财务按钮。
有没有人有想法如何创建这样的按钮(就像第一张图片中的红色按钮)?现在可能有更现代和更简单的解决方案。重要的是地平线是凹凸的(向下侧),而不是凸起的(中间向下的椭圆)。就像图中所示。
我必须更多地了解CSS-3和最新的技术,以提高我的技能。
英文:
I need a simple button with a color gradient and a transparent gradient layover faking a light glare. In the old days I created just the button with color gradient (red to dark red) and set a layer with a transparent gradient (white, with opacity 0.25 to 0.50) over the button.
<br />
But I have big problem with a concave horizon line:<br />
<br />
I marked it here with a theoretically line, just for better understanding.
<br />
Tryout code on fiddle:<br />
I've been experimenting a bit with concave background settings here. But then I get no transparent history.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
#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;
}
<!-- language: lang-html -->
<div id="wrapper">
<div id="test">B1</div>
<div id="test">B2</div>
</div>
<!-- end snippet -->
But my CSS 2 skills are totally outdated.
Hence the question of whether there is a better solution for my financial button.
Does anyone have an idea how I can create such a button (like the red one in the first picture)? There may now be much more modern and simpler solutions. - It is important that the horizon line is concave (laterally downwards) and not convex (ellipse downwards in the middle). Exactly as shown in the graphic.
I have to deal a lot more with CSS-3 and the latest technologies to improve my skills.
答案1
得分: 3
你可以通过一个元素和径向渐变来实现这个效果。
button {
width: 64px;
height: 64px;
border: 0;
border-radius: 3px;
background: radial-gradient(circle at 50% 150px, #B31609, #D5000C 69%, #DD3C3F 50%, #F0A696 100%);
}
<button></button>
英文:
You can accomplish this with one element and a radial gradient.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
button {
width: 64px;
height: 64px;
border: 0;
border-radius: 3px;
background: radial-gradient(circle at 50% 150px, #B31609, #D5000C 69%, #DD3C3F 50%, #F0A696 100%);
}
<!-- language: lang-html -->
<button></button>
<!-- end snippet -->
答案2
得分: 2
以下是您要翻译的内容:
你可以叠加多个渐变,一个在另一个之上。我使用了一个透明的圆形径向渐变来淡化按钮的边缘,然后放置了一个线性渐变在其下。然后,您可以使用CSS自定义属性来设置按钮的颜色,任何颜色都可以。以下是代码。在rgba()属性中调整不透明度值以获得您想要的效果。
已编辑,因为半径不能是百分比值,所以我使用了自定义属性,以便按钮半径随着按钮大小的变化而缩放,这样您可以使用不同宽度的按钮,它会正常缩放。
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
#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;
}
<!-- language: lang-html -->
<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>
<!-- end snippet -->
英文:
You can overlay multiple gradients, one on top of the other. I've used a transparent circular radial gradient to fade out the button with an edge then put a linear gradient below it. You can then use CSS custom properties to set the button colour to whatever you like. Code below. Twiddle about with the opacity values in the rgba() property to get the effect you're looking for.
Edited as the radius can't be a percentage value, I've used a custom property so that the button radius scales with the button size so you can use buttons of different widths and it'll scale up okay.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
#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;
}
<!-- language: lang-html -->
<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>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论