CSS 有没有办法在一个元素上使用两个 CSS3 框阴影?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8556604/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 02:25:27  来源:igfitidea点击:

Is there a way to use two CSS3 box shadows on one element?

css

提问by Benjamin Humphrey

I'm trying to replicate a button style in a Photoshop mock-up that has two shadows on it. The first shadow is an inner lighter box shadow (2px), and the second is a drop shadow outside the button (5px) itself.

我正在尝试在具有两个阴影的 Photoshop 模型中复制按钮样式。第一个阴影是内部较亮框阴影 (2px),第二个阴影是按钮外部的阴影 (5px)。

enter image description here

enter image description here

In Photoshop this is easy - Inner Shadow and Drop Shadow. In CSS I can apparently have one or the other, but not both at the same time.

在 Photoshop 中,这很容易 - 内阴影和投影。在 CSS 中,我显然可以拥有其中一个,但不能同时拥有两者。

If you try the code below in a browser, you'll see that the box-shadow overrides the inset box-shadow.

如果您在浏览器中尝试下面的代码,您将看到 box-shadow 覆盖了 inset box-shadow。

Here's the inset box shadow:

这是插入框阴影:

box-shadow: inset 0 2px 0px #dcffa6;

And this is what I would like for the drop shadow on the button:

这就是我想要的按钮上的阴影:

box-shadow: 0 2px 5px #000;

For context, here's my full button code (with gradients and all):

对于上下文,这是我的完整按钮代码(带有渐变和所有):

button {
    outline: none;
    position: relative;
    width: 160px;
    height: 40px;
    font-family: 'Open Sans', sans-serif;
    color: #fff;
    font-weight: 800;
    font-size: 12px;
    text-shadow: 0px 1px 3px black; 
    border-radius: 3px;
    background-color: #669900;
    background: -webkit-gradient(linear, left top, left bottom, from(#97cb52), to(#669900));
    background: -moz-linear-gradient(top, #97cb52, #669900);
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#97cb52', endColorstr='#669900');
    box-shadow: inset 0 2px 0px #dcffa6;
    box-shadow: 0 2px 5px #000;
    border: 1px solid #222;
    cursor: pointer;
}

回答by David says reinstate Monica

You can comma-separate shadows:

您可以用逗号分隔阴影:

box-shadow: inset 0 2px 0px #dcffa6, 0 2px 5px #000;

回答by JayC

Box shadows can use commasto have multiple effects, just like with background images (in CSS3).

框阴影可以使用逗号来产生多种效果,就像背景图像(在 CSS3 中)一样。