homepage Welcome to WebmasterWorld Guest from 23.23.8.131
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / CSS
Forum Library, Charter, Moderators: not2easy

CSS Forum

    
macros or define
are macros possible
jeremy

10+ Year Member



 
Msg#: 940 posted 11:26 am on Apr 26, 2003 (gmt 0)

I was wondering if it was possible to define something eg a color with (in C) #define Brown #804040 and then use the term "Brown" eveywhere I wanted to have #804040, in the CSS file. This would make it easier to change colours on a global scale with just one edit, rather than looking for all instances of the colour.

I am new to CSS so excuse the lame questions. Thanks.

 

aspdaddy

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 940 posted 11:51 am on Apr 26, 2003 (gmt 0)

I did similar for an intranet in ASP, using a config file and some globals.e.g
G_BGCOLOR = "#f5f5f5"

Couldnt get it into the .css file so the next best thing was inline styles:
<table style="background-color:<%=G_BGCOLOR%>">

Its not a great solution , a macro would be much nicer but I couldnt figure out how.

heini

WebmasterWorld Senior Member heini us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 940 posted 12:29 pm on Apr 26, 2003 (gmt 0)

Jeremy, where do you see the advantage of globally changing "brown" over globally changing "#804040"?

Also, a way to organize your sheets is to make as much central definitons as possible, which also has the effect of cutting down on the size of the sheets.

jeremy

10+ Year Member



 
Msg#: 940 posted 9:29 pm on Apr 26, 2003 (gmt 0)

Hello heini,
The advantage is that I would not have to do a global replace. I would only have to change it once - at the (eg #define Brown #804040 to #define Brown #CCCfff) and all instances where "Brown" occurs would change automatically and now be #CCCfff instead of #804040

This method is used in many languages (C pascal etc )
at the top of the file you have stuff like
#define Brown #804040
#define MyEmail billG@microsoft.com

and in the source you have something like.....

Background-color = Brown;
...
...
email = MyEmail;

These may occur many times within the file. The advantage of a macro is that I do not have to find them, just change the definition at the top of the file (or included file) and the preprocessor or compiler does the rest for me. It is neat & tidy.

I am not sure yet how sophisticated this CSS stuff is, I used to be a C,C++ programmer and old habits die hard.

I will probably just move all things that I might want to change from time to time (like aesthetics) to a separate file like color.css and have the definitions there. At least they will be in one place.

grahamstewart

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 940 posted 2:39 am on Apr 27, 2003 (gmt 0)

No there are no macro or define capabilities in CSS.
I agree it might be handy in some cases, but it would lead to a whole new category of bugs too :)

If you are really keen on coding like this then you could write your CSS in PHP. Like this...

<?php
header( 'Content-Type: text/css' );
define( 'BROWN', '#804040' );
define( 'PINK', '#daa');
?>

.myclass {
font: <?php echo BROWN?>;
background: <?php echo PINK?>;
border: 1px solid <?php echo BROWN?>;
}

and then link to it as an external stylesheet in the normal way..

<link rel="stylesheet" type="text/css" href="styles.php">

To my mind this is a bit too clunky to use effectively so I can't really recommend it - but if you are already using a php stylesheet for other reasons (e.g. browser switching) then it might be useful to you.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / CSS
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved