简体   繁体   English

如何使盒子阴影的不透明度仅是阴影而不是div

[英]How to make the opacity of box-shadow exclusive to the shadow and not the div

This is my code 这是我的代码

.navbar {
width: 100%;
height: 70px;
position: fixed;
background-color: white;
box-shadow: 0 0 1em #1d1d1d;    
}

Every time I run something under this eg something that has a background color the shadow goes under it and so does the rest of the content. 每次我在此背景下运行某些内容时,例如具有背景色的内容,阴影就会在其下移动,其余内容也会在其下移动。 Should I just layer it? 我应该把它分层吗?

Based on the code you have, this should work. 根据您的代码,这应该可以工作。 I think there is a possibility two things are happening here: 我认为这里可能发生两件事:

  1. Check if you are setting the z-index on the elements that are going above your fixed nav to a greater value or you could set a z-index value on .navbar to see if that helps. 检查是否将固定导航上方的元素的z-index设置为更大的值,或者可以在.navbar上设置z-index值以查看是否有帮助。

  2. The other possibility is that you are setting the elements that are overlapping your .navbar to absolute . 另一种可能性是,您正在将与.navbar重叠的元素设置为absolute If that is the case, and this is necessary, you could set the z-index on .navbar to a greater value. 如果是这样,并且有必要,则可以将.navbar上的z-index设置为更大的值。

Hope that helps. 希望能有所帮助。

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

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