简体   繁体   English

左侧和右侧的阴影框阴影

[英]Slanted box shadow on left and right side

I am trying to make slanted box shadow on both sides of a div, which I have added here as an image. 我正在尝试在div的两侧制作倾斜的框阴影,我已在此处将其添加为图像。 在此处输入图片说明 The red part is indicating here shadow. 红色部分表示此处有阴影。 actually color is not solid , it should gradually decrease when it is moving to outside from border. 实际上颜色不是固定的 ,当颜色从边界移到外部时,颜色应逐渐减少。

Try this: 尝试这个:

 div{ width: 200px; height: 200px; border:1px solid black; background: white; } div:before{ content:' '; display:block; width: 200px; height:200px; background: linear-gradient(transparent, black); position: fixed; transform: matrix3d(1.1,0,0.00,0,0.00,0.71,0.71,0.0007,0,-0.71,0.71,0,0,37,0,1); z-index: -1; } 
 <div>Hello</div> 

Here is my contribution hope it gives you a baseline. 这是我的贡献,希望它能为您提供基准。

  .box { width: 150px; height: 200px; position: relative; padding-left: 25px; padding-right: 25px; } .box-content { display: flex; align-items: center; justify-content: center; z-index: 2; background-color: white; border: 2px solid black; width: 100%; height: 100%; position: relative; } .box::before { content: ''; display: block; border-top: 0; border-bottom: 180px solid transparent; border-right: 25px solid red; position: absolute; left: 0; bottom: 0; } .box::after { content: ''; display: block; border-top: 0; border-bottom: 180px solid transparent; border-left: 25px solid red; position: absolute; right: -4px; bottom: 0; } 
 <div class="box"> <div class="box-content"> Box </div> </div> 

Using transform: skew() applied to the div's before and after 使用transform: skew()应用于div beforeafter

jsFiddle 1 jsFiddle 1

code: 码:

 #test { width: 150px; height: 220px; line-height: 220px; background-color: white; border: 2px black solid; text-align: center; position: relative; margin: 10px 150px; } #test:before, #test:after { width: 150px; height: 200px; position: absolute; bottom: 0; left: -11px; z-index: -1; content: " "; display: block; background-color: red; transform: skew(5deg, 0); } #test:after { transform: skew(-5deg, 0); left: 11px; } 
 <div id="test">Box</div> 


EDIT : to give the shadow effect some real blur with gradient and transparency, we could make use of linear-gradient background with two rgba() values, as well as CSS blur() (1) filter. 编辑:要使阴影效果具有渐变和透明性,我们可以使用具有两个rgba()值的linear-gradient背景以及CSS blur() (1)过滤器。

jsFiddle 2 jsFiddle 2

code: 码:

 #test { width: 150px; height: 220px; line-height: 220px; background-color: white; border: 2px black solid; text-align: center; position: relative; margin: 10px 150px; } #test:before, #test:after { width: 150px; height: 200px; position: absolute; bottom: 0; left: -11px; z-index: -1; content: " "; display: block; background: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.7)); transform: skew(5deg, 0); filter: blur(2px); } #test:after { transform: skew(-5deg, 0); left: 11px; } 
 <div id="test">Box</div> 


Notes: 笔记:

(1) browser support for CSS filter (1) 浏览器对CSS过滤器的支持

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM