[英]Background-image doesn't show up in a div
It doesn't even show up in the Chrome Inspector. 它甚至没有显示在Chrome Inspector中。 I am doing something wrong but don't know what.
我做错了事,但不知道怎么办。
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<title>Trio - Bootstrap Responsive Agency/Portfolio HTML5 Template</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- CSS & Favicon -->
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous" />
<link rel="stylesheet" href="css/stylesheet.css">
<!-- scripts -->
</head>
<body>
<div class="wrapper">
<header>
<div id=="container header_div">
</div>
</header>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</body>
</html>
And the CSS is: CSS是:
body {width: 100%; height: 100%; position: relative;}
header {height: 100vh;}
#header_div {
background-image: url(../images/header_background.jpg);
background-position: center;
background-size: cover;
}
I have added all of the background-properties in the css and the div has a size. 我在css中添加了所有background-properties,并且div具有大小。
I see several things that can cause the issue: 我看到可能导致此问题的几件事:
<div id=="container header_div">
. <div id=="container header_div">
。 Should be single. By doing this, I was able to see a background image in my test. 这样,我可以在测试中看到背景图像。 I hope this helps.
我希望这有帮助。
Not exist <div id="container header_div">
in you css, change to <div id="header_div">
在您的CSS中不存在
<div id="container header_div">
,请更改为<div id="header_div">
body {width: 100%; height: 100%; position: relative;} header {height: 100vh;} #header_div { background-image: url(http://www.planwallpaper.com/static/images/desktop-year-of-the-tiger-images-wallpaper.jpg); background-position: center; background-size: cover; }
<!DOCTYPE html> <html lang="en-US"> <head> <meta charset="utf-8"> <title>Trio - Bootstrap Responsive Agency/Portfolio HTML5 Template</title> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <!-- CSS & Favicon --> <link rel="icon" type="image/x-icon" href="favicon.ico" /> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous" /> <link rel="stylesheet" href="css/stylesheet.css"> <!-- scripts --> </head> <body> <div class="wrapper"> <header> <div id="header_div"> </div> </header> </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> </body> </html>
I had a similar issue like this before. 我以前有类似的问题。 This is what I did.
这就是我所做的。 I set the div background to just this
background: url("./images/header_background.jpg");
我将div背景设置为此
background: url("./images/header_background.jpg");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.