Jump to content

Variables in CSS


pmdesign

Recommended Posts

Hi,I just wanna ask you if you can use variables in CSS. For example:i have two colors defined:.t1 {color: Red;}.t2 {color: Blue;}If i define other class t3 but want to use the t1 color, is there anyway to use it as a variable in t3 ? For example:.t3 {color: t1.color}so to be equivalent to .t3 {color: Red;}I need it because it's gonna be so useful if you wanna change the colors of the CSS by cnahging only the main color t1.The questions is also about the other options: background, font .... s.o

Link to comment
Share on other sites

I may be wrong, but I don't think there is any way of doing that. Although, even if you can I'm not sure it would be a good idea. If two styles are always going to have an attribute that is the same, pull the common attributes into a new style since logically they're independent and then in all the places you want that color attribute you use both styles.That also achieves your aim of only one place to update.Hope that helps!

Link to comment
Share on other sites

I may be wrong, but I don't think there is any way of doing that. Although, even if you can I'm not sure it would be a good idea. If two styles are always going to have an attribute that is the same, pull the common attributes into a new style since logically they're independent and then in all the places you want that color attribute you use both styles.That also achieves your aim of only one place to update.Hope that helps!

Thanks a lot, i'll try it :)
Link to comment
Share on other sites

When it comes to XSLT I know you can achieve it if you put the CSS stylesheet inside and use XSL variable to manipulate it.However, when it comes to separated styleshhets, it's a bit more complex. I'm not sure and I hope that someone could answer me this one, but I think that server side scripts could be binded with any file, as long as they have their respective extensions. For example style.php is not for sure an XHTML page. It could be a CSS stylesheet. So there you go: you should be able to put server side variables inside a stylesheet. I'm not sure if this is possible and/or wise though.

Link to comment
Share on other sites

When it comes to XSLT I know you can achieve it if you put the CSS stylesheet inside and use XSL variable to manipulate it.However, when it comes to separated styleshhets, it's a bit more complex. I'm not sure and I hope that someone could answer me this one, but I think that server side scripts could be binded with any file, as long as they have their respective extensions. For example style.php is not for sure an XHTML page. It could be a CSS stylesheet. So there you go: you should be able to put server side variables inside a stylesheet. I'm not sure if this is possible and/or wise though.

10q so much. It's a great idea. I may use a php script to generate my CSS file :)Много благодаря :)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...