How to apply box-shadow only on 3 sides? [duplicate]

不羁的心 提交于 2021-01-29 14:11:59

问题


I use my CSS page below. He applies a box-shadow on the 4 sides.

I want it to be applied only to the right, bottom and left.

How to apply box-shadow only on 3 sides ?

-webkit-box-shadow: 0 0 10px rgba(0,0,0,0.22);
-moz-box-shadow: 0 0 10px rgba(0,0,0,0.22);
-ms-box-shadow: 0 0 10px rgba(0,0,0,0.22);
-o-box-shadow: 0 0 10px rgba(0,0,0,0.22);
box-shadow: 0 0 10px rgba(0,0,0,0.22);

回答1:


You can always do something like:

.shadow-box {
  background-color: #ddd;
  margin: 0px auto;
  padding: 10px;
  width: 220px;
  box-shadow: 0px 8px 10px gray, 
    -10px 8px 15px gray, 10px 8px 15px gray;
 }
<div class="shadow-box">Box with shadows</div>



回答2:


box-shadow supports only X & Y offset, but you can achieve box-shadow to 3 directions, by providing appropriate value to the offsets.

Tip : In chrome via inspect element you can easily get the exact values and preview that before using it.

Please refer to snippet below.

#boxShadow {
    display: block;
    margin: auto;
    height: 300px;
    width: 300px;
    background: #cdcdcd;
    box-shadow: 0px 5px 8px 0px #3fab83;
}
<br><div id="boxShadow">
</div>


来源:https://stackoverflow.com/questions/51731699/how-to-apply-box-shadow-only-on-3-sides

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!