html - Float 无法覆盖我的整个背景。这是为什么?
问题描述
我的 html 文件中有两个 div,宽度均为 50%。左边的位置是固定的,右边的位置必须是滚动的。我把它设为浮动。问题是,我的浮动 div 背景周围有一个空白区域:
我的代码:
for (i = 0; i < 100; i++) {
document.write(" <br>");
}
.left {
flex: 1;
left: 0;
width: 50%;
background-color: #ffc30b;
height: 100vh;
position: fixed;
top: 0;
}
.left p {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.right {
background-size: cover;
width: 50%;
background-color: black;
float: right;
}
<body>
<section id="about">
<div class="left">
<p class="header">ABOUT</p>
</div>
<div class="right">
<div class="aboutimg"><img src="img.png" alt="me|Jessa" width="200" height="200" /></img>
</div>
</div>
</section>
</body>
解决方案
尝试添加这个
body {
margin: 0;
}
推荐阅读
- bash - !< 是什么意思?
- inno-setup - 我可以在 Inno Setup 中将 .isl 文件用于带有预处理器指令的消息吗?
- validation - 何时/何地在 FastAPI 中使用正文/路径/查询/字段?
- ansible - Ansible:检查提示值
- excel - EXCEL:将两个动态数组与多列组合
- x86 - 对 x86 保护模式内存布局感到困惑
- kubernetes - nginx-ingress 反向代理后端子路径
- php - 通过钩子在 WooCommerce 单个产品页面中显示自定义字段值
- python - 从同一个文件创建数据库和表的最佳方法是什么?
- javascript - 如何从本地 html 文件中获取服务器内容?