gpt4 book ai didi

php - CSS 背景图片未加载,似乎找不到图片

转载 作者:太空宇宙 更新时间:2023-11-03 19:36:31 25 4
gpt4 key购买 nike

我正在制作个人网站,但我的 CSS 背景图像似乎无法正常工作。该网站的链接是 http://distorts.me/new/它似乎找不到图像,因为它没有加载,它只是一个白色区域。 (对不起,标点符号不太识字)我正在使用 chrome。

样式.css

    body {
background-image: url("http://distorts.me/new/includes/background.png");
color: #C0C0C0;
}

.navbar {
margin-bottom: 0;
border-radius: 0;
}

.row.content {height: 450px}

.sidenav {
padding-top: 20px;
background-color: #808080;
height: 100%;
font-size: 20px;
}

a {
color: #C0C0C0;
text-decoration: none;
}

a:hover {
text-decoration: none;
color: #404040;
}

footer {
background-color: #555;
color: white;
padding: 15px;
}

@media screen and (max-width: 767px) {
.sidenav {
height: auto;
padding: 15px;
}
.row.content {height:auto;}
}

索引.php

    <html lang="en">
<!-- George M. -->
<!-- 2/26/16 -->
<?php
include 'includes/head.php';
?>
<body oncontextmenu="return false" background="includes/background.png">
<header class="container-fluid text-center" style="background-color: #404040;">
<h1>George M. - Welcome</h1>
</header>
<div class="container-fluid text-center">
<div class="row content">
<div class="col-sm-2 sidenav" style="height: 183%">
<p><a href="index-2.html">Home</a></p>
<p><a href="/about">About Me</a></p>
<p><a href="/services">Services</a></p>
<p><a href="/contact">Contact</a></p>
</div>
<div class="col-sm-8 text-middle">
<h1>Welcome</h1>
<p>test</p>
<hr>
<h3>Test</h3>
<p>test</p>
</div>
</div>
</div>
<footer id="foot" class="container-fluid text-center">
</footer>
<script type="text/javascript">
document.getElementById('foot').innerHTML =
"<p>&copy " + new Date().getFullYear() + " Distorts | George M. All rights reserved. <span style='color: #808070;'>Made by George M.</span>"
</script>
</body>
</html>

头.php

<head> 
<title>George M | Home</title>
<link rel="shortcut icon" href="/favicon.ico">
<meta name="author" content="Distorts">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="style.css">
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js" type="text/javascript"></script>
</head>

最佳答案

当代码正确时,最有可能导致问题的问题是缓存。一些 Web 托管服务器具有缓存预配置,并且由于您使用的是 PHP,您可以简单地发送阻止缓存的 PHP header - 在 header.php 的最顶部添加这些行:

<?php
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>

另一个可以使用的技巧是timestamping/querystring - 这种方法基本上强制浏览器重新加载文件,因为它的 URL 与之前加载的不同。所以很自然地,我们添加了时间变量(因为时间总是在变化)。其他开发人员通过添加版本查询来使用此方法,但这需要更多维护。

用 PHP 添加文件时间戳:

<link rel="stylesheet" type="text/css" href="style.css?t=<?php echo date('YmdHis');">

输出

<link rel="stylesheet" type="text/css" href="style.css?t=20160227182425">

文件版本示例

<link rel="stylesheet" type="text/css" href="style.css?v=2.1">

此外,请记住 CSS 背景路径是相对于 CSS 文件本身的,而不是 HTML 文档。 html中的链接是相对于html文档的,CSS中的链接是相对于CSS文件的。因此,引用图像的正确方法如下:

background-image: url("includes/background.png");

关于php - CSS 背景图片未加载,似乎找不到图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35674085/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com