[英]Background-image not showing with CSS
Can't figure out why the background image is not showing... Used / and \\ , short and long path... Any cue would be appreciated. 无法弄清楚为什么背景图像没有显示...用过的/和\\,短路径和长路径...任何提示将不胜感激。 Thanks
谢谢
<head>
<title>Restaurant Lambda</title>
<link href="css/style.css" rel="stylesheet">
</head>
<body>
<!--Menu-->
<header>
<div class="container">
<nav class="topnav">
<a href="#home" class="active">Home</a>
<a href="#news">About</a>
<a href="#contact">Ingredients</a>
<a href="#contact">Menu</a>
<a href="#contact">Reviews</a>
<a href="#contact">Reservation</a>
</div>
</nav>
</header>
</body>
.countainer {
background: url("C:/Users/lili/Desktop/LesManifestesTest/img/Bg.png") no-repeat 0 0;
}
As well as the typo in your class name (the extra 'u' in container/countainer), your syntax is incorrect. 以及类名中的错字(容器/计数器中的额外“ u”),您的语法也不正确。 You are closing the
nav
after you've closed the div
, instead of the other way around. 关闭
div
之后,您将关闭nav
,而不是相反。
Correct these errors, and your image should show correctly (given that your path is correct) 更正这些错误,并且图像应该正确显示(假设您的路径正确)
.container { height: 100vh; background: url("https://cdn.pixabay.com/photo/2018/06/30/09/31/background-image-3507320__340.jpg") no-repeat 0 0; } nav { text-align: center; } nav a { color: white; /*added for better visibility*/ font-weight: bold; }
<body> <!--Menu--> <header> <div class="container"> <nav class="topnav"> <a href="#home" class="active">Home</a> <a href="#news">About</a> <a href="#contact">Ingredients</a> <a href="#contact">Menu</a> <a href="#contact">Reviews</a> <a href="#contact">Reservation</a> </nav> </div> </header> </body>
There are actually 3 reasons this might be happening. 实际上可能有3个原因。
<div class="container">
but in your css, you have <div class="container">
但在CSS中, .countainer {
background: url("C:/Users/lili/Desktop/LesManifestesTest/img/Bg.png") no-repeat 0 0;
}
So you would need to fix the spelling error. 因此,您需要修复拼写错误。
.container {
background: url("folder/imagename") no-repeat 0 0;
}
In the code block, you've got <div>
then <nav>
but you end with </div>
then </nav>
so after reformatting your code, it should look like 在代码块中,先输入
<div>
然后<nav>
<div>
然后以</div>
然后</nav>
结尾,因此在重新格式化代码后,它看起来应该像
<div class="container">
<nav class="topnav">
<a href="#home" class="active">Home</a>
<a href="#news">About</a>
<a href="#contact">Ingredients</a>
<a href="#contact">Menu</a>
<a href="#contact">Reviews</a>
<a href="#contact">Reservation</a>
</nav>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.