如何使此 ::before 元素的阴影位于整个 header div 下方?
How do I make the shadow of this ::before element go underneath the entire header div?
我对 CSS 很讨厌。我在我的项目中使用了 React 和 Styled Components,但我设法在 codepen 中重现了这个问题。
我有一个固定的 header,它有一个阴影,以及一个由 ::before 选择器创建的圆圈(我的实际代码中顶部有一个徽标)。
我希望圆的 box-shadow 位于 header div 下方,这样它看起来就像一个单一的形状。这可能吗?我将不胜感激任何指导。我试着对 z-index 和堆叠进行了一些研究,但我什么也做不了。
这里有一个link来个码笔:https://codepen.io/twistedspoon/pen/ExNbrLa
body {
background: Gainsboro;
margin: 0;
}
.headerbox {
background: white;
display: flex;
align-items: center;
justify-content: space-between;
height: 60px;
position: fixed;
top: 0;
width: 100%;
transition: 0.6s;
box-shadow: 1px 2px 24px 0px rgba(0, 0, 0, 0.45);
}
.logobox {}
.logobox::before {
transition: none;
margin: none;
position: absolute;
content: '';
width: 72px;
height: 72px;
border-radius: 50%;
background: white;
transform: translateY(30%);
bottom: 0px;
box-shadow: 1px 2px 24px 0px rgba(0, 0, 0, 0.45);
z-index: -1;
}
<div class="headerbox">
<p>some title text</p>
<div class="logobox"></div>
<div>
<a>a link</a>
</div>
</div>
删除所有框阴影并试试这个:
.headerbox {
filter: drop-shadow(0px 0px 24px rgba(0, 0, 0, 0.45));
}
body {
background: Gainsboro;
margin: 0;
}
.headerbox {
background: white;
display: flex;
align-items: center;
justify-content: space-between;
height: 60px;
position: fixed;
top: 0;
width: 100%;
transition: 0.6s;
filter: drop-shadow(0px 0px 24px rgba(0, 0, 0, 0.45));
}
.logobox {}
.logobox::before {
transition: none;
margin: none;
position: absolute;
content: '';
width: 72px;
height: 72px;
border-radius: 50%;
background: white;
transform: translateY(30%);
bottom: 0px;
z-index: -1;
}
<div class="headerbox">
<p>some title text</p>
<div class="logobox"></div>
<div>
<a>a link</a>
</div>
</div>
我对 CSS 很讨厌。我在我的项目中使用了 React 和 Styled Components,但我设法在 codepen 中重现了这个问题。
我有一个固定的 header,它有一个阴影,以及一个由 ::before 选择器创建的圆圈(我的实际代码中顶部有一个徽标)。
我希望圆的 box-shadow 位于 header div 下方,这样它看起来就像一个单一的形状。这可能吗?我将不胜感激任何指导。我试着对 z-index 和堆叠进行了一些研究,但我什么也做不了。
这里有一个link来个码笔:https://codepen.io/twistedspoon/pen/ExNbrLa
body {
background: Gainsboro;
margin: 0;
}
.headerbox {
background: white;
display: flex;
align-items: center;
justify-content: space-between;
height: 60px;
position: fixed;
top: 0;
width: 100%;
transition: 0.6s;
box-shadow: 1px 2px 24px 0px rgba(0, 0, 0, 0.45);
}
.logobox {}
.logobox::before {
transition: none;
margin: none;
position: absolute;
content: '';
width: 72px;
height: 72px;
border-radius: 50%;
background: white;
transform: translateY(30%);
bottom: 0px;
box-shadow: 1px 2px 24px 0px rgba(0, 0, 0, 0.45);
z-index: -1;
}
<div class="headerbox">
<p>some title text</p>
<div class="logobox"></div>
<div>
<a>a link</a>
</div>
</div>
删除所有框阴影并试试这个:
.headerbox {
filter: drop-shadow(0px 0px 24px rgba(0, 0, 0, 0.45));
}
body {
background: Gainsboro;
margin: 0;
}
.headerbox {
background: white;
display: flex;
align-items: center;
justify-content: space-between;
height: 60px;
position: fixed;
top: 0;
width: 100%;
transition: 0.6s;
filter: drop-shadow(0px 0px 24px rgba(0, 0, 0, 0.45));
}
.logobox {}
.logobox::before {
transition: none;
margin: none;
position: absolute;
content: '';
width: 72px;
height: 72px;
border-radius: 50%;
background: white;
transform: translateY(30%);
bottom: 0px;
z-index: -1;
}
<div class="headerbox">
<p>some title text</p>
<div class="logobox"></div>
<div>
<a>a link</a>
</div>
</div>