简体   繁体   English

盒子里面的盒子阴影

[英]Box shadow inside box

I want to set box shadow inside a box or div but only at right and left sides. 我想在box或div中设置box shadow,但只能在左右两侧设置。 I want something like this below. 我想要下面这样的东西。 Please help me. 请帮我。

在此处输入图片说明

为了使它只出现在侧面,您必须具有两个不同的集合:

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

You can create one inner div and one outer div. 您可以创建一个内部div和一个外部div。 Then you need to set the shadow separately for both divs. 然后,您需要分别为两个div设置阴影。

 .outer, .inner { width: 200px; height: 50px; display: inlin-block; } .outer { -webkit-box-shadow: inset 10px 0px 23px -9px rgba(0,0,0,0.75); -moz-box-shadow: inset 10px 0px 23px -9px rgba(0,0,0,0.75); box-shadow: inset 10px 0px 23px -9px rgba(0,0,0,0.75); } .inner { -webkit-box-shadow: inset -10px 0px 23px -9px rgba(0,0,0,0.75); -moz-box-shadow: inset -10px 0px 23px -9px rgba(0,0,0,0.75); box-shadow: inset -10px 0px 23px -9px rgba(0,0,0,0.75); } 
 <div class="outer"> <div class="inner"></div> </div> 

Or you can use also one div, with 2 inset parameters: 或者,您也可以使用一个带有2个插入参数的div:

 .outer { width: 200px; height: 50px; display: inlin-block; -webkit-box-shadow: inset 10px 0px 23px -9px rgba(0,0,0,0.75), inset -10px 0px 23px -9px rgba(0,0,0,0.75); -moz-box-shadow: inset 10px 0px 23px -9px rgba(0,0,0,0.75), inset -10px 0px 23px -9px rgba(0,0,0,0.75); box-shadow: inset 5px 0 8px -5px #000,inset -5px 0 8px -5px #000, inset -10px 0px 23px -9px rgba(0,0,0,0.75); } 
 <div class="outer"> </div> 

And what about a linear-gradeint solution: 线性gradeint解决方案又如何呢?

 .box { width:200px; height:100px; background: linear-gradient(to left,#ccc , transparent 20%), linear-gradient(to right,#ccc , transparent 20%); } 
 <div class="box"> </div> 

You can do this using the two div's. 您可以使用两个div来做到这一点。 check the below code. 检查以下代码。 But it will great if you can use the background image. 但是,如果您可以使用背景图片,那就太好了。

<div class="div1">
   <div class="div2"><div>
 <div>

.div1 {
    width: 200px;
    height: 100px;
    border: 1px solid #c51e1e;
    margin: 50px;
    overflow: hidden;
}
.div2 {
    width: 80%;
    height: 100px;
    margin: 0 auto;
    box-shadow: 0px 0px 27px 17px #d6cdcd;
}

try this with html: 尝试使用html:

<div id="box"></div>

and css: 和CSS:

#box {
  border: 1px solid;
  position: relative;
  overflow: hidden;
}
#box:before {
  content: "";
  box-shadow: 0px 0px 20px 10px #888888;
  position: absolute;
  height: 100%;
  width: 0px;
}
#box:after {
  content: "";
  box-shadow: 0px 0px 20px 10px #888888;
  position: absolute;
  height: 100%;
  width: 0px;
  right: 0px;
  top: 0;
}

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

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