html - 不确定如何设置背景图像中图像的正确路径

标签 html css

目前我只想将图像作为背景放置到 div 中。我可以通过键入 http://example.com/storage/uploads/icons/heart.png 在我的浏览器中访问图像,但我不确定在我的 background-image 中写什么: url(""); 因为我使用 Laravel 作为后端,所以我不确定默认情况下我在文件夹层次结构中的确切位置。

最佳答案

A) if http://example.com/ is'nt the root of your domain:

background-image: url("http://example.com/storage/uploads/icons/heart.png");

例如:

div {
  width: 100px;
  height: 100px;
  background-image: url("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRDAYrQr9qgT2W00EV_CoCahFki3Vw4lSMNt81k9FCSTXoKT8TY2w");
  background-size: 100% 100%;
}
<div></div>	

B) if http://example.com/ is your domain, so depending on the html file location to the storage folder ,for example: if path storage folder and html file be same,use this:

background-image: url("storage/uploads/icons/heart.png");

C) if path html file is: http://example.com/HtmlFolder/index.html and path image is http://example.com/storage/uploads/icons/heart.png,so use ../ a folder to go back:

background-image: url("../storage/uploads/icons/heart.png");

关于html - 不确定如何设置背景图像中图像的正确路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50402681/

相关文章:

javascript - Canvas 绘制带有线性渐变的填充圆 Angular 矩形

jquery - 显示 div 的 x,y 并随着 div 移动更新值

css 100% 宽度当水平滚动条

Android 浏览器视口(viewport)和媒体查询不适用于自动换行和图像缩放

javascript - 用于更改文本框值的 html 链接

html - 如何摆脱我的 div 的这个额外的空白区域?

html - 如何在母版页中使用内联 CSS

html - 将 Html 样式表附加到 Angular 应用程序

html - 如何将 reveal.js 中整个文本(标题、标题和正文)的位置更改为左上角?

javascript - 无法将 CSS 和 JavaScript 链接到 HTML