View Full Version : Symbolic constants in CSS?
jfriend
Oct-19-2005, 08:39 AM
I'm a releative CSS newbie, but a long time software developer. I've made only a few modest changes to my site so far, but am playing with some more significant changes.
One thing that struck me is that setting all these widths in a smugmug CSS stylesheet is like programming without variables and symbolic constants. Every single number is a hard-coded numeric value. If I had to write code that way, it would be hard to maintain and hard to understand.
Where this struck me is if you want to do something that sounds fairly simple like change the width of your site, you have to track down many, many constants and figure out how much to change them. It's easy to miss a bunch of them.
Is this just a limitation in CSS2? Are there any options in CSS2 that can make this better? I heard a rumor of support for JS expressions in IE. Is that a standard or a Microsoft one-off?
--John
Mike Lane
Oct-19-2005, 08:44 AM
Yes, there is a way to do this. I saw a tutorial once. Let me see if I can find it again (hopefully it's in my delicious).
Mike Lane
Oct-19-2005, 10:01 AM
Yes, there is a way to do this. I saw a tutorial once. Let me see if I can find it again (hopefully it's in my delicious).
Okay I found the pages I was looking for, that's the good news. The bad news is that the only way I can find to do this is with server-side scripting of the various constants. Obviously we can't do server-side scripts of our own on smugmug so that solution won't work. Here are the two relavent pages:
http://www.devarticles.com/c/a/Web-Style-Sheets/CSS-Constants/
http://www.shauninman.com/plete/2005/08/css-constants
The quote of the day is:
"...as far as I know, current browser CSS implementations ignore values they don’t understand and there is no reliable way to get the string contents of a CSS file."
The question is, if you have an inline CSS declaration, could you not parse it with javascript once the inline script has loaded?
Javascriptors, I call on you once again!
http://developer.mozilla.org/en/docs/DOM:stylesheet
after looking over that link, you *should* be able to parse out your stylesheet by looping through the cssRules array of a stylesheet object, examine the rules, then update your stylesheet using the stylesheet.insertRule method.
however, according to the W3 DOM Level 2 (http://www.w3.org/TR/1998/REC-CSS2-19980512/syndata.html#q8) a cssRule consists of a selector and a declaration block, so that kinda sucks.
sounds like a heckuva lot of work to me. maybe the guy who wanted to change the width of his pages to 430px can tackle this as his next project.
Okay I found the pages I was looking for, that's the good news. The bad news is that the only way I can find to do this is with server-side scripting of the various constants. Obviously we can't do server-side scripts of our own on smugmug so that solution won't work. Here are the two relavent pages:
http://www.devarticles.com/c/a/Web-Style-Sheets/CSS-Constants/
http://www.shauninman.com/plete/2005/08/css-constants
The quote of the day is:
"...as far as I know, current browser CSS implementations ignore values they don’t understand and there is no reliable way to get the string contents of a CSS file."
The question is, if you have an inline CSS declaration, could you not parse it with javascript once the inline script has loaded?
Javascriptors, I call on you once again!
Mike Lane
Oct-19-2005, 10:45 AM
sounds like a heckuva lot of work to me. maybe the guy who wanted to change the width of his pages to 430px can tackle this as his next project.
:lol3
vBulletin® v3.8.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.