gpt4 book ai didi

html - 如何让 Box-Shadow 在另一个元素上方渲染?

转载 作者:行者123 更新时间:2023-12-03 23:59:18 25 4
gpt4 key购买 nike

我有以下代码:

body {
margin: 0px;
padding: 0px;
}

a {
text-decoration: none;
color: black;
}

a:visited {
color: black;
}

#superheader {
width: auto;
height: 100px;
position: relative;
}

#superheader p {
font-family: Sansation;
font-size: 50px;
display: block;
line-height: 0.0
}

#superheader table {
border: none;
height: 100px;
display: block;
}

#header {
height: 140px;
box-shadow: 0em 0em 1em 0.2em grey;
position: relative;
background-color: #E6E6E6;
padding-left: 70px;
padding-right: 70px;
font-family: sans-serif;
}

.menuelement {
width: 100px;
height: 40px;
text-align: center;
padding-left: 10px;
padding-right: 10px;
float: left;
position: relative;

}

.menuelement:hover {
background-color: dimgrey;
color: lightgray;
}

#header>a {
line-height: 2.5;
}

#page {
background-color: white;
font-family: sans-serif;
margin-left: 70px;
margin-right: 70px;
height: 100%;
margin-bottom: 2em;
box-shadow: 0em 0.6em 0.5em grey;
padding-left: 2em;
padding-right: 2em;
padding-top: 0.1em;
height: 6000px;
position: relative;
}
<div id="header">
<div id="superheader">
<div style="margin: auto; width: 630px;">
<table>
<tr>
<td><img src="images/memoji.png" width="100px" height="100px" alt="Icon" </td> <td>
<p>Title</p>
</td>
</tr>
</table>
</div>
</div>
<a href="page1.html">
<div class="menuelement">page1</div>
</a>
<a href="index.html">
<div class="menuelement">Startseite</div>
</a>
<a href="page2.html">
<div class="menuelement">page2</div>
</a>
</div>
<div id="page">
<h1>First Headline</h1>
<h2>Second Headline</h2>
<p>Some text.</p>
</div>

header-div 的 box-shadow 不在 page-div 上方呈现,而是隐藏在其下方。
如何让 box-shadow 呈现在 page-div 上,以便在那里可见?
非常感谢您帮助我!

最佳答案

box-shadow header 被 page 选择器隐藏,因为 header 选择器堆栈顺序低于 page 选择器。

所以需要修改header选择器的栈顺序高于page选择器。

这可以使用 z-index 来完成。并将 z-index: 1 (任何高于 0 的值,因为默认 z-index: auto (= 0))添加到 #header 类,你会看到 box-shadow.

body {
margin: 0px;
padding: 0px;
}

a {
text-decoration: none;
color: black;
}

a:visited {
color: black;
}

#superheader {
width: auto;
height: 100px;
position: relative;
}

#superheader p {
font-family: Sansation;
font-size: 50px;
display: block;
line-height: 0.0
}

#superheader table {
border: none;
height: 100px;
display: block;
}

#header {
height: 140px;
box-shadow: 0em 0em 1em 0.2em grey;
position: relative;
background-color: #E6E6E6;
padding-left: 70px;
padding-right: 70px;
font-family: sans-serif;

z-index: 5;
}

.menuelement {
width: 100px;
height: 40px;
text-align: center;
padding-left: 10px;
padding-right: 10px;
float: left;
position: relative;

}

.menuelement:hover {
background-color: dimgrey;
color: lightgray;
}

#header>a {
line-height: 2.5;
}

#page {
background-color: white;
font-family: sans-serif;
margin-left: 70px;
margin-right: 70px;
height: 100%;
margin-bottom: 2em;
box-shadow: 0em 0.6em 0.5em grey;
padding-left: 2em;
padding-right: 2em;
padding-top: 0.1em;
height: 6000px;
position: relative;
}
<div id="header">
<div id="superheader">
<div style="margin: auto; width: 630px;">
<table>
<tr>
<td><img src="images/memoji.png" width="100px" height="100px" alt="Icon" </td> <td>
<p>Title</p>
</td>
</tr>
</table>
</div>
</div>
<a href="page1.html">
<div class="menuelement">page1</div>
</a>
<a href="index.html">
<div class="menuelement">Startseite</div>
</a>
<a href="page2.html">
<div class="menuelement">page2</div>
</a>
</div>
<div id="page">
<h1>First Headline</h1>
<h2>Second Headline</h2>
<p>Some text.</p>
</div>

关于html - 如何让 Box-Shadow 在另一个元素上方渲染?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64393144/

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