html - 为什么背景图像不显示?(CSS)
问题描述
我有一个导航栏,但我想要一个填充页面其余部分的背景图像,我尝试这样做以及其他许多事情,但我无法让它工作。
我一直在尝试在此站点上找到的其他解决方案,例如尝试使用 URL 图像而不是本地图像,放置背景颜色也不起作用。这是我的代码。
* {
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
nav {
display: flex;
justify-content: space-around;
align-items: center;
min-height: 8vh;
background-color: white;
font-family: 'Poppins', sans-serif;
}
body {
border-left: 2vh solid white;
border-right: 2vh solid white;
border-bottom: 2vh solid white;
}
.Logo {
color: black;
}
.nav_links {
display: flex;
width: 30%;
justify-content: space-around;
}
.nav_links a {
color: black;
text-decoration: none;
}
.nav_links a:hover {
color: grey;
}
.nav_links li {
list-style: none;
}
.content {
background-image: url(https://static6.depositphotos.com/1000747/604/v/950/depositphotos_6049093-stock-illustration-baker-illustration.jpg);
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
}
<meta charset="utf-8">
<title></title>
<meta name="description" content="">
<link href="https://fonts.googleapis.com/css?family=Poppins&display=swap" rel="stylesheet">
<nav>
<div class="Logo">
<h4>El Pan de Antes</h4>
</div>
<ul class="nav_links">
<li><a href="#">Inicio</a></li>
<li><a href="#">Nuestros Productos</a></li>
<li><a href="#">Sobre Nosotros</a></li>
</ul>
</nav>
<div class="content">
</div>
解决方案
您的内容部分是空的,我只是将其更改为 body 标记,并且它的工作还删除了边框以清楚起见,再次添加它我只是评论它
*{
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
nav{
display: flex;
justify-content: space-around;
align-items: center;
min-height: 8vh;
background-color: white;
font-family: 'Poppins', sans-serif;
}
body{
/*border-left: 2vh solid white;
border-right: 2vh solid white;
border-bottom: 2vh solid white;*/
}
.Logo{
color: black;
}
.nav_links{
display: flex;
width: 30%;
justify-content: space-around;
}
.nav_links a {
color: black;
text-decoration: none;
}
.nav_links a:hover{
color: grey;
}
.nav_links li{
list-style: none;
}
body {
background-image: url("https://cdn.pixabay.com/photo/2017/08/30/01/05/milky-way-2695569_960_720.jpg");
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta name="description" content="">
<link rel="stylesheet" href="styles.css">
<link href="https://fonts.googleapis.com/css?family=Poppins&display=swap" rel="stylesheet">
</head>
<body>
<nav>
<div class="Logo">
<h4>El Pan de Antes</h4>
</div>
<ul class="nav_links">
<li><a href="#">Inicio</a></li>
<li><a href="#">Nuestros Productos</a></li>
<li><a href="#">Sobre Nosotros</a></li>
</ul>
</nav>
<div class="content">
sdsads
dasdsa
asdas
</div>
</body>
</html>
推荐阅读
- typeorm - 具有嵌套 ManyToOne 关系的 OneToMany 关系返回损坏的关系实体
- flow - 在totalJS Flow中获取参数?
- ios - 什么是默认线程
- excel - Excel 添加截至日期的小时数,不包括周末和节假日
- angularjs - 为什么重定向到在角度路由中不起作用?
- machine-learning - 特征工程,处理缺失数据
- javascript - 如何按降序更改奇数/偶数div中的背景颜色
- laravel - 有没有可能从 Laravel 中的模型生成数据库的方法?
- xamarin.android - 为什么我的 Google OAuth2 登录正常工作,而忽略了我的应用程序签名密钥库
- ios - 更改可以嵌套在 Swift 中的键的 JSON 值