html - PHP 文件中的背景图像未显示

标签 html css background-image

我有一个包含 html 代码并显示用户帐户的 php 文件。我想为背景添加一个图像并重复它。但是,我几乎什么都试过了,还是无法显示!该图像位于名为“style”的文件夹中,该文件夹位于其余 php 文件所在的位置。

<?php session_start();?>
<html>

<head>
<title>My Account</title>
<style>
    body{
        background-image: url("/style/ebook_back.png");

    }
    h2{
        background-color: red;
      }
</style>
</head>

<body>
<?php
    //Some PHP code...
?>

<h1>My Account</h1> <hr>
<h2>Account Details</h2>
<h3>Check & Modify personal details</h3>

<hr>
<h2>My Orders</h2>
<h3>Check & Modify my orders</h3>

<hr>
<h2>My Wishlist</h2>
<h3>Check & Update my wishlist</h3>

<?php More PHP code...?>
</body>

</html>

h2 的背景色显示正确,但图像不显示!尺寸为 200 x 200 像素

我做错了什么?

最佳答案

您提供了错误的路径。在开头添加点或删除第一个斜线。

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

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

关于html - PHP 文件中的背景图像未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16263442/

相关文章:

css - 在 Rails/bootstrap 中,为什么背景图像不能正确拉伸(stretch)?

javascript - 如何使用链接更改背景图像

php - 在所有网页上保留我的页眉和页脚?

html - 是什么 特点?

javascript - D3 : adding style and class to DIV results in styles discarded

Javascript 切换隐藏

javascript - html5 Canvas 在调整大小时重绘

javascript - 获取内联 CSS 属性值,即使它被覆盖

javascript - 为什么对象解构不起作用?

css - 背景图像不会显示使用 HTML5 样板