首页 > 解决方案 > 如何使用 css 样式标签更改 html 背景图像?

问题描述

我一直在尝试使用 css 为我的 html 页面设置背景图像,但我遇到了一些问题。当我在下面使用此代码时,它虽然有效

<style>
html  {background-image: url("D:/HtML5/astronomytweak/img/andromeda.jpg");}
</style>

但是当我尝试使用我想上传到在线服务器的这个时,它不起作用。下面是我正在尝试使用但无法正常工作的那个。

<style> html {background-image: url("img/andromeda.jpg");} </style>

我需要帮助来应对这个挑战。先感谢您。

标签: css

解决方案


尝试设置相对路径(./)

<style>
html  {background-image: url("./img/andromeda.jpg");}
</style>

推荐阅读