用php改变css背景图片 [英] Change css background-image with php

查看:497
本文介绍了用php改变css背景图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为这个网站做个配置文件,并且我想要做一个像facebook一样的元素的封面照片。我碰到的问题是,首先如何保存封面的背景图像?就像,我可以将图像的url保存在数据库中,但是我怎么能够把它放在css中呢?

I'm doing a profile for this website, and I wanted to do a cover photo like element like facebook has. The problem I have ran into is, first how do I save the background image of the cover? Like, I can save the url of the image in the database, but how would I possibly be able to put it in css?

我不想只是说:

I do not really want to just put:

<div style="background-image:url(<?php echo $imageUrl?>) no-repeat center center fixed">
</div>

这看起来非常丑陋。是否有其他方法?

That looks really ugly markup. Is there some other way?

推荐答案

唯一的其他选择是将它放在样式标记中,或者让php生成外部CSS文件。

The only other options would be to put it in a style tag, or have php generate an external CSS file.

对于标签,您可以做

For the tag you'd do

<style>
  div { background-image: url(<?php echo $imageURL;?>); }
</style>

这比内嵌HTML样式更简洁。

That is a bit cleaner than inline HTML styling.

这篇关于用php改变css背景图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆