CSS3背景加上图像的透明度



我在按钮上有坚实的背景颜色,我正在寻找一些CSS(3?),这些CSS(3?)会叠加半透明的白色,但仅在颜色上方最高的50%。我正在寻找一种非毕业,非图像的光泽效果。

如果不使用图像,该如何完成?如果解决方案不支持较旧的浏览器,则可以。

编辑: BookCasey的答案似乎可以正常工作,除了字体也透明了...

<!DOCTYPE html>
<html>
<head>
<style>
a
{
    display: inline-block;
    padding:30px;
    background: salmon;
    position: relative;
    text-align: center;
    text-decoration:none;
    color:#000;
    font-size:20pt;
    font-weight:bold;
}
a:before
{
    content: '';
    width: 100%;
    height: 50%;
    background: rgba(255,255,255,0.5);
    position: absolute;
    top: 0;
    left:0;
}
</style>
</html>
<body>
<div>
    <a href="#">Test Link</a>
</div>
</body>
</html>

谢谢,

安迪

在相对父母上使用绝对定位的伪元素。

演示

a {display: block; width: 100px; height: 50px; background: salmon; position: relative;}
a:before {
    content: '';
    width: 100%;
    height: 50%;
    background: rgba(255,255,255,.5);
    position: absolute;
    top: 0;
    left:0;
}

另一种完全不同的技术(在评论中提到但没有解释)是使用具有硬色的CSS3梯度。

a {display: block; width: 100px; height: 50px; position: relative;
  background: -webkit-gradient(linear, 50% 100%, 50% 0%, color-stop(50%, rgba(255, 255, 255, 0)), color-stop(50%, rgba(255, 255, 255, 0.5))), salmon;
  background: -webkit-linear-gradient(bottom, rgba(255, 255, 255, 0) 50%, rgba(255, 255, 255, 0.5) 50%), salmon;
  background: -moz-linear-gradient(bottom, rgba(255, 255, 255, 0) 50%, rgba(255, 255, 255, 0.5) 50%), salmon;
  background: -o-linear-gradient(bottom, rgba(255, 255, 255, 0) 50%, rgba(255, 255, 255, 0.5) 50%), salmon;
  background: linear-gradient(bottom, rgba(255, 255, 255, 0) 50%, rgba(255, 255, 255, 0.5) 50%), salmon;}​

demo

最新更新