html - 背景图像覆盖整个屏幕但有一个奇怪的边距
问题描述
我定义了一个 div 来在背景中设置一个图像以覆盖整个屏幕。但是有一个奇怪的边缘,我无法摆脱。
我查看了代码,发现没有任何迹象表明我已经设置了这些边距。当在 css 类中将位置设置为固定时,图像是这样的:
但是当我没有将位置设置为“固定”时,它看起来像这样:
app.component.html
<main>
<router-outlet></router-outlet>
</main>
login.component.html
<div class="back">
<form action="" method="post" class="form">
<img src="../../../assets/toolbar_logo_blue.png" alt="logo" style="width: 100%;max-width: 500px">
<div class="container">
<label><b>Email</b>
<input type="text" placeholder="Digite seu email" name="uname" required>
</label>
<label>
<b>Senha</b>
<input type="password" placeholder="Digite sua senha" name="psw" required>
</label>
<button type="submit" class="loginbutton">Logar como: <h4 style="display: inline-block; color: darkcyan;padding: 5px"> Clínica</h4></button>
<div>
<label class="switch">
<input type="checkbox" checked="checked" name="type">
<span class="slider round">
</span>
</label>
</div>
</div>
</form>
</div>
login.component.css
.form {
background-color: transparent;
border: #2196F3;
padding: auto;
margin: auto;
justify-content: center;
width: 50%;
display: block;
height: 50%;
text-align: center;
clear: both;
}
.back {
background: url("../../../assets/background_paper.jpg") no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
height: 100%;
width: 100%;
position: fixed;
}
/* Add padding to containers */
.container {
padding: 16px;
width: 70%;
margin: 0 auto;
text-align: center;
}
.container2 {
background-color: rgba(0, 3, 115, 0.21);
float: right;
text-align: center;
}
.loginbutton {
background: cornflowerblue;
opacity: 0.8;
border-radius: 10%;
/*width: 10%;*/
color: black;
/*height: 10%;*/
}
我知道我稍后会外包的内联样式。
解决方案
事实证明,我现在只是将边距设置为 -8px,它就成功了。使用 chrome 开发人员工具,我发现它是 html 元素中 8px 的边距集,但我找不到它在代码中声明。感谢您的回答和评论。
推荐阅读
- react-native - 使用 docker 运行一个反应原生应用程序,使用 expo
- java - Java IPAddress 库和非零 CIDR
- sql - 我应该如何创建关系模式才能在 oracle 数据库中“加入”?我需要将哪些列与哪个键关联?
- javascript - React JS,道具验证
- python - SQL 一对多关系 - 以 JSON 格式检索数据的查询
- r - 根据条件复杂的另一行调整数据框行
- node.js - 我对 react.js 中的 state.map 有问题,没有显示数据
- android - 在颤振飞镖中,我必须为包和应用程序 ID 添加相同的名称
- mysql - 查询根据条件返回值
- mysql - JSON_Extract 错误:函数 json_extract 的参数 1 中的 JSON 文本无效:“缺少对象成员的名称。”