Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 07-04-2008, 09:06 AM   #1
Brujah
Beer Money Baron
 
Brujah's Avatar
 
Industry Role:
Join Date: Jan 2001
Location: brujah / gmail
Posts: 22,157
Variables in CSS?

Is it possible to use variables in CSS? I have an html layout. I want to use one main css for structure and just decide on the colors based on a variable if possible. Can it be done?
__________________
Brujah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-04-2008, 09:08 AM   #2
darksoul
Confirmed User
 
darksoul's Avatar
 
Join Date: Apr 2002
Location: /root/
Posts: 4,997
it can't be done with pure css afaik. But look into dynamically loading css files with javascript
that'll get your stuff done.
__________________
1337 5y54|)m1n: 157717888
BM-2cUBw4B2fgiYAfjkE7JvWaJMiUXD96n9tN
Cambooth
darksoul is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-04-2008, 01:11 PM   #3
harvey
Confirmed User
 
harvey's Avatar
 
Industry Role:
Join Date: Jul 2001
Location: 127.0.0.1
Posts: 9,266
I'm not sure what do you exactly need, but if I'm getting you right, of course you can, and it's quite easy, check http://interfacelab.com/variables-in-css-via-php/

in action (from http://sperling.com/examples/pcss/ )

in action (from http://sperling.com/examples/pcss/)

Code:
<?php
header("Content-type: text/css");
$color = "green";        // <--- define the variable 
echo <<<CSS   
/* --- start of css --- */
h2
	{
	color: $color;  /* <--- use the variable */
	font-weight: bold;
	font-size: 1.2em;
	text-align: left;
	}
/* --- end of css --- */
CSS;
?>

I already made a few projects using this method and works like a charm, in conjunction with XSL/XML environments is a real help then again, not sure if this is what you're looking for
__________________
This post is endorsed by CIA, KGB, MI6, the Mafia, Illuminati, Kim Jong Il, Worldwide Ninjas Association, Klingon Empire and lolcats. Don't mess around with it, just accept it and embrace the truth
harvey is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-04-2008, 01:14 PM   #4
harvey
Confirmed User
 
harvey's Avatar
 
Industry Role:
Join Date: Jul 2001
Location: 127.0.0.1
Posts: 9,266
aaah, now I see you want html and not php... well, there are ways, but don't remember exactly how since I didn't pay much attention because it was too much work for the result
__________________
This post is endorsed by CIA, KGB, MI6, the Mafia, Illuminati, Kim Jong Il, Worldwide Ninjas Association, Klingon Empire and lolcats. Don't mess around with it, just accept it and embrace the truth
harvey is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-04-2008, 01:23 PM   #5
StuartD
Sofa King Band
 
StuartD's Avatar
 
Join Date: Jul 2002
Location: Outside the box
Posts: 29,903
Strangely enough, you can do it in IE but not any other browser. Go figure, the one browser that does CSS the worst....

In IE... you can do this:

<style>
#column1 {
width: expression(document.getElementsByTagName('body')[0]) / 2);
}
</style>

In IE, you can use javascript within the expression brackets. But every other browser will ignore it.

You can
StuartD is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-04-2008, 01:27 PM   #6
StuartD
Sofa King Band
 
StuartD's Avatar
 
Join Date: Jul 2002
Location: Outside the box
Posts: 29,903
Wow, gfy makes posting slow...

Anyway, I was going to finish with:

You can do it that way to avoid using php if you don't know it or have it readily available but php will give you way more control.
StuartD is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-04-2008, 01:34 PM   #7
Kard63
Confirmed User
 
Kard63's Avatar
 
Join Date: Nov 2003
Location: 237 619 975
Posts: 8,944
What is your avatar Stuart? It looks like a fox turning into a sea creature and humping the earth.
__________________
Kard63 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-04-2008, 01:35 PM   #8
StuartD
Sofa King Band
 
StuartD's Avatar
 
Join Date: Jul 2002
Location: Outside the box
Posts: 29,903
Quote:
Originally Posted by Kard63 View Post
What is your avatar Stuart? It looks like a fox turning into a sea creature and humping the earth.
Heh, pretty damn close actually.

It's a 3d representation of the Firefox logo.
StuartD is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-04-2008, 01:56 PM   #9
brandonstills
Confirmed User
 
brandonstills's Avatar
 
Join Date: Dec 2007
Location: Chatsworth, CA
Posts: 1,964
If you use a dynamic language like PHP to generate it. It's more difficult if the file ends in .css because you would have to configure apache to treat it as PHP (which also slows the request down), but if you do it as an embedded CSS in a PHP file this is definitely possible.

There was some talk of CSS variables recently but until it becomes standard in all browsers I don't see a point in looking into it.
brandonstills is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-04-2008, 02:05 PM   #10
Brujah
Beer Money Baron
 
Brujah's Avatar
 
Industry Role:
Join Date: Jan 2001
Location: brujah / gmail
Posts: 22,157
Some good suggestions, and I can definitely work with these. Thanks.
__________________
Brujah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.