CSS 仅左侧和右侧的框阴影

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17416881/
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-29 23:22:35  来源:igfitidea点击:

Box-Shadow Only on Left and Right

css

提问by L84

I am attempting to create an inset box-shadow on an element that only has the shadow on the left and right. I cannot get it to work.

我试图在一个只有左右阴影的元素上创建一个插入框阴影。我无法让它工作。

Here is the box-shadow I tried:

这是我试过的盒子阴影:

 box-shadow: inset 10px 0px 25px 0px rgba(0,0,0,0.45);

I will add another one for the right side. The problem is this setting also shows the shadow slightly on the top and bottom and I cannot get it to not show and still show a shadow on the left side. Is this possible?

我会为右侧添加另一个。问题是这个设置还在顶部和底部稍微显示了阴影,我无法让它不显示并且仍然在左侧显示阴影。这可能吗?

jsFiddle

js小提琴

回答by Antony

Use a negative value on spread-radius (4th value)to shrink the shadow. This can hide the unwanted top and bottom shadow.

spread-radius上使用负值(第 4 个值)来缩小阴影。这可以隐藏不需要的顶部和底部阴影。

box-shadow: inset 25px 0px 25px -25px rgba(0,0,0,0.45), inset -25px 0px 25px -25px rgba(0,0,0,0.45);

See DEMO.

演示