CSS Attributes and Variables

I have discovered one of the(my) main problems with CSS is that when I get a good template together with 6 or 7 cells a container and perhaps a nested container <div> too, then give them all borders and cell padding, which have to be included in the total width of the page the numbers start getting a bit haywire.

If I want to change one of the numbers I have to change all of them. some of the browsers esp. IE calculate in different ways and I've often ended up wasting time by nudging a cell over one pixel at a time until it lines up with some other part of the page.

I'm not organised and I find adjusting values a bit tiresome. My idea was to do something like this

<script>
var cssAttribute = "100px"
</script>

<style type="text/css">
div#test {
width: 500px;
height:"cssAttribute";
background-color: #456789;
}
</style>
</head>
<body>
<div id="test">test</div>
</body>....etc, I was purely guessing at the syntax, please don't laugh

But of course nothing's that simple. Can someone tell me if it's possible to assign a variable instead of a value to a CSS attribute.
If I could do that I would be able to assign fixed widths and heights based on other elements on the page, so if I changed one value i.e. the height of a container, the rest of the things would change with it.Originally posted by bol
Can someone tell me if it's possible to assign a variable instead of a value to a CSS attribute.

nope though many wouldn't mind this :PIt only works with IE.
height:expression(document.documentElement.clientHeight - 200);

It is not a good idea to use it to "fix" a problem.
The description of your problems indicates trouble with the "box-model".
Using a valid DTD and correct implementation of css should avoid any problems.

Show us your page if you require help.Thanks.... The page is working ok to tell the truth, it's really just that the time consumed by setting up the numbers correctly could be saved if one were able to assign variables to hold the attribute values, for example if the container width and height attributes were set to the sum of the widths and heights of the things within it.Of Course This is Possible if your using
Server Side Code

I Have ColdfusionMX on my server so it is possible to use
Variables in style Sheets
Not boasting or anything but makes life alot easer
Mattmatt.carter.25 wrote:
Of Course This is Possible if your using Server Side Code
You can also do it with JavaScript, but it was a css question.

It will be implemented in css3 (<!-- m --><a class="postlink" href="http://www.w3.org/Style/CSS/current-work">http://www.w3.org/Style/CSS/current-work</a><!-- m -->)Originally posted by Fang
You can also do it with JavaScript, but it was a css question.

It will be implemented in css3 (<!-- m --><a class="postlink" href="http://www.w3.org/Style/CSS/current-work">http://www.w3.org/Style/CSS/current-work</a><!-- m -->)

CSS is making its way to OOP!! jk.I must say that i love css
 
Back
Top