简体   繁体   English

如何使用background-image:用php

[英]How to use background-image: with php

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. 目前,这个CSS不起作用。 No background image is displayed. 没有显示背景图像。

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');

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. 如果使用第二个选项,则需要从css规则中删除该元素的背景图像URL。 Hope it helps 希望能帮助到你

It depenteds to where is your css file , put your css file and image file into same place, and try below 它依赖于你的css文件在哪里,把你的css文件和图像文件放到同一个地方,然后尝试下面

background-image: url("frame.jpg");

Or you can use / to start from root folder. 或者您可以使用/从根文件夹开始。

background-image: url("/frame.jpg");

Read this. 读这个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM