这是我的CSS代码:
body
{
background-image:url("C:\xampp\htdocs\try\images\bg.jpg");
}
这是我的 html 代码:
<!DOCTYPE html>
<html>
<head> <title> HOPE Centre </title> </head>
<link rel="stylesheet" type="text/css" href="style1.css" media="all" />
<body>
<div id="wrapper">
<!--header-->
<header>
<div class="header">
<h1><img src="C:\xampp\htdocs\try\images\logo.png" alt="HOPE Centre" style="width:146px;height:83px></h1>
<nav>
<ul id="top_nav">
<li><a href="index.html">Home</a></li>
<li><a href="#">Sign up</a></li>
<li><a href="#">LogIn</a></li>
</ul>
</nav>
</div> <!--end of div header-->
</header>
<!--main navigation-->
<div class="nav">
<a href="index.php">Home</a>
<a href="#">About</a>
<a href="#">How to Help</a>
<a href="#">Contact</a>
</div> <!--end of div nav-->
</body>
</html>
标题中的图像也没有显示。
上面的代码只显示白色背景。我使用的是 Google Chrome 版本 37.0.2062.103 m。
我应该如何解决这个问题?
最佳答案
尝试
body{background-image:url("../try/images/bg.jpg");}
或
body{background-image:url("../../try/images/bg.jpg");}
在哪里
Start with "/" returns to the root directory and starts here
Start with "../" moves one directory backwards and starts here
Start with "../../" moves two directories backwards and starts here
关于html - 背景图像不显示在 html css 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25773588/