html - 父视图的阴影消失了
问题描述
div
嗨,当将孩子移动到sticky
父母下方时,我面临着阴影消失的问题div
。
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
html, body{
min-height: 100% !important;
}
body{
margin: 0;
background-color: #470c77;
}
.header{
width: 100%;
height: 50px;
background-color: rgb(238, 238, 238);
box-shadow: 0px 0px 6px 2px #000000;
position: sticky;
top: 0;
}
.view{
width: 100%;
height:25%;
background-color: rgb(255, 255, 255);
position: fixed;
top: 50px;
z-index: 0;
}
</style>
</head>
<body>
<div class="header">
<!-- TODO:- Some elements here -->
<div class="nav">
<!-- TODO:- Some Elements Here -->
<div class="view">
</div>
</div>
</div>
</body>
</html>
主要问题是阴影从nav
. 如果我做到top: 50px;
了,view
那么阴影就会出现。但身体的背景颜色也可见。
预期布局:
请帮助我仅使用 CSS 解决此问题。
解决方案
尝试这个:
<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
html, body{
min-height: 100% !important;
}
body{
margin: 0;
background-color: #470c77;
}
.header{
width: 100%;
height: 50px;
background-color: rgb(238, 238, 238);
-webkit-box-shadow: inset 0 -7px 3px -5px rgba(0,0,0,0.65);
-moz-box-shadow: inset 0 -7px 3px -5px rgba(0,0,0,0.65);
box-shadow: inset 0 -7px 3px -5px rgba(0,0,0,0.65);
position: sticky;
top: 0;
}
.view{
width: 100%;
height:25%;
background-color: rgb(255, 255, 255);
position: fixed;
top: 50px;
z-index: 0;
}
</style>
</head>
<body>
<div class="header">
<!-- TODO:- Some elements here -->
<div class="nav">
<!-- TODO:- Some Elements Here -->
<div class="view">
</div>
</div>
</div>
</body>
</html>
要隐藏背景,您可以增加.view
height
推荐阅读
- list - Flutter AnimatedList 更新列表长度失败
- netty - 无法分配请求的地址:连接
- ms-access-2007 - 插入语句中的“输入参数值”
- javascript - 带有 Formik 的 Material UI 选择器,用于日期和时间组件,带有秒数
- javascript - Mocha 使用在全局范围内定义的类型测试 TypeScript
- react-admin - React-admin - 重定向未经身份验证的用户而不显示管理 UI
- flutter - 在颤振中管理空安全插件和非空安全插件
- python - 有一个 ModuleNotFoundError!在 Django
- karate - 空手道 UI:如何在单个功能文件中并行运行多个场景
- ruby-on-rails - 自动递增 ID / 主键中的“间隙”会导致任何问题吗?