我在CSS中使用background-image
属性设置了背景图像。通过大部分页面,它完美地运作。但是,当它到达某个<h2>
元素时,背景图像不会显示在为<h2>
定义的整个区域中。
我该如何解决这个问题?
html {
background-image: url("https://wallpaperscraft.com/image/city_hong_kong_night_clouds_lights_58330_3840x2160.jpg");
}
&#13;
<html>
<head>
<meta charset="utf-8">
<title>Dimstone</title>
<meta name="description" content="Building the website">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">
</script>
<link rel="stylesheet" href="main.css">
</head>
<body id="b-override">
<h2 id="header">header</h2>
<div id="top-navbar">
<ul class="nav navbar-nav navbar-left">
<li><a class="nav-link" href="#">HomePage</a></li>
<li><a class="nav-link" href="#">SignUp</a></li>
<li><a class="nav-link" href="#">About</a></li>
</ul>
</div>
</body>
</html>
&#13;
答案 0 :(得分:0)
不是h2
,而是body
标记(ID为#b-override
)
添加此CSS:
body#b-override {
background: transparent;
}
html {
background-image: url("https://wallpaperscraft.com/image/city_hong_kong_night_clouds_lights_58330_3840x2160.jpg");
}
body#b-override {
background: transparent;
}
<html>
<head>
<meta charset="utf-8">
<title>Dimstone</title>
<meta name="description" content="Building the website">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">
</script>
<link rel="stylesheet" href="main.css">
</head>
<body id="b-override">
<h2 id="header">header</h2>
<div id="top-navbar">
<ul class="nav navbar-nav navbar-left">
<li><a class="nav-link" href="#">HomePage</a></li>
<li><a class="nav-link" href="#">SignUp</a></li>
<li><a class="nav-link" href="#">About</a></li>
</ul>
</div>
</body>
</html>