如何使用background-image:用php
16lz
2021-01-22
How can I use background-image: url() in conjunction with php in order to obtain the directory of the image I would like to display.
我如何结合php使用background-image:url()来获取我想要显示的图像的目录。
CSS
CSS
.imageGallery {
width: 960px;
position: relative;
background-image: url('<?php bloginfo("template_directory");?>/images/visitus.png');
}
Currently, this css does not work. No background image is displayed.
目前,这个CSS不起作用。没有显示背景图像。
HTML
HTML
<div class="imageGallery">
</div>
For example:
例如:
this works fine
这很好用
<img src='<?php bloginfo("template_directory");?>/images/home.png' class="headImage" />
but this doesn't
但事实并非如此
background-image: url('<?php bloginfo("template_directory");?>/images/visitus.png');
2 个解决方案
#1
1
You can try this two options bellow
你可以试试这两个选项
CSS
CSS
.imageGallery {
width: 960px;
position: relative;
background-image: url('images/visitus.png');
}
HTML with inline CSS
带内联CSS的HTML
<div class="imageGallery" style="background-image: url('<?php bloginfo("template_directory");?>/images/visitus.png')">
</div>
If you use the second option, you need to remove background image url from your css rule for that element. Hope it helps
如果使用第二个选项,则需要从css规则中删除该元素的背景图像URL。希望能帮助到你
更多相关文章
- 在PHP中将PDF文档转换为预览图像,而无需安装Ghostscript
- 我需要PHP页面显示mysql数据库中的BLOB图像
- php怎么读取MYSQL数据到radio选项
- 如何使用mysql在php文件夹中快速更改图像名称?
- 视差滚动与图像仅通过徽标透明度
- 具有固定宽度网格的引导程序和应跨越窗口宽度的图像
- 从文本框值生成条形码图像
- Div高度为图像高度,图像宽度为div宽度
- 如何在HTML选择选项列表中保留空间hi