Topic: How would I be able to do this in CSS?
background-image: url('http://domain.tld/attr(title).png');
where the title attribute says "image" so the actual URL should be http://domain.tld/image.png. This is bugging me so much...
You are not logged in. Please login or register.
PunBB Forums → Programming → How would I be able to do this in CSS?
background-image: url('http://domain.tld/attr(title).png');
where the title attribute says "image" so the actual URL should be http://domain.tld/image.png. This is bugging me so much...
If you mean you want to the name of the image file to vary then the answer is you can't, css has no support for variables in style declarations whatsoever. The only way to do it is to generate the css dynamically.
I will dynamically make the title element to the specified image name and via css retrieve the content. The attr(attribute) function can retrieve the contents of specified attribute; it's just that I don't know how to do so in my example. More concise:
<style type="text/css">
#test::after {
content: url('http://www.yahoo.com/attr(test).png')
}
</style>
<div id="test" title="main">
...
</div>
Doing this yiels no output.
What I'd advise you to do, is to reference a PHP script as your stylesheet instead of a static CSS file. With some mod_rewrite magic, you could even name the file '.css'. Then you can just do whatever you want in the PHP code as long as you do 'header("Content-Type: text/css; charset=iso-8859-1");' and only output CSS code from the file.
PunBB Forums → Programming → How would I be able to do this in CSS?
Powered by PunBB, supported by Informer Technologies, Inc.