gpt4 book ai didi

html - 将阴影和 z-index 应用于绝对定位元素

转载 作者:太空宇宙 更新时间:2023-11-03 21:13:45 25 4
gpt4 key购买 nike

我正在尝试在导航栏中实现一个凸起,导航栏应该有一个框阴影......但是底部也需要它......不知何故我不能把凸起放在导航栏,这是一个已知问题还是我遗漏了什么?非常感谢。

body {
background: beige;
}

.c-header {
background: white;
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.8);
height: 60px;
position: fixed;
width: 100%;
z-index: 9999;
}

.c-site-nav {
align-content: center;
display: flex;
justify-content: space-between;
}
.c-site-nav ul {
margin-left: 0;
}
.c-site-nav__item {
display: flex;
justify-content: space-around;
list-style: none;
width: 40%;
}
.c-site-nav__item a {
font-size: 20px;
color: grey;
display: inline-block;
text-decoration: none;
}

.c-logo {
position: absolute;
left: 50%;
transform: translate(-50%, 0);
padding: 0;
position: absolute;
top: 15px;
width: 45px;
z-index: 1;
}
.c-logo::after {
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.8);
position: absolute;
left: 50%;
transform: translate(-50%, 0);
background: white;
border-radius: 50%;
content: '';
height: 60px;
position: absolute;
width: 60px;
z-index: -100;
}
<header class="c-header">
<div class="c-logo">
</div>
<nav class="c-site-nav">
<ul class="c-site-nav__item">
<li><a href="/">asd</a></li>
<li><a href="/ueber_uns">asd</a></li>
<li><a href="/">asd</a></li>
</ul>
<ul class="c-site-nav__item">
<li><a href="/">asd</a></li>
<li><a href="/">asd</a></li>
<li><a href="tel:+49234234234">34234234</a></li>
</ul>
</nav>
</header>

最佳答案

我不知道这是否是预期的结果,但我设法通过将

  <div class="c-logo">

在标题元素之外。

body {
background: beige;
}

.c-header {
background: white;
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.8);
height: 60px;
position: fixed;
width: 100%;
z-index: 9999;
}

.c-site-nav {
align-content: center;
display: flex;
justify-content: space-between;
}
.c-site-nav ul {
margin-left: 0;
}
.c-site-nav__item {
display: flex;
justify-content: space-around;
list-style: none;
width: 40%;
}
.c-site-nav__item a {
font-size: 20px;
color: grey;
display: inline-block;
text-decoration: none;
}

.c-logo {
position: absolute;
left: 50%;
transform: translate(-50%, 0);
padding: 0;
position: absolute;
top: 15px;
width: 45px;
z-index: 1;
}
.c-logo::after {
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.8);
position: absolute;
left: 50%;
transform: translate(-50%, 0);
background: white;
border-radius: 50%;
content: '';
height: 60px;
position: absolute;
width: 60px;
z-index: -100;
}
<header class="c-header">
</div>
<nav class="c-site-nav">
<ul class="c-site-nav__item">
<li><a href="/">asd</a></li>
<li><a href="/ueber_uns">asd</a></li>
<li><a href="/">asd</a></li>
</ul>
<ul class="c-site-nav__item">
<li><a href="/">asd</a></li>
<li><a href="/">asd</a></li>
<li><a href="tel:+49234234234">34234234</a></li>
</ul>
</nav>
</header>
<div class="c-logo">

关于html - 将阴影和 z-index 应用于绝对定位元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43977193/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com