Forum Moderators: open
I need to set 'min-width' & 'max-width' rules to two divs and aren't sure about the Java Script for it to make it work in IE6 and below.
The two divs in question have a width 0f 75% and are centered on top of each other. My Javascript is in a seperate CSS file with the following rule on it:
#container, #base {
width: expression(document.body.clientWidth < 680? "680px" : document.body.clientWidth > 980? "980px" : "auto");
}
When this is applied I think it only applies these rules to the body?
How do I apply these rules to the #container and #base divs to be set at 75% of the body until they reach below 680px of over 980px?
Please help.
Regards
Erdy
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<style>
#container, #base {
border: solid 1px red;
min-width: 680px;
max-width: 980px;
width: 75%;
_width: expression( document.body.clientWidth < 926? '680px':
document.body.clientWidth > 1325? '980':'75%'
);
}
</style>
</head>
<body>
body
<div id="container">container</div>
<div id="base">base</div>
</body>
</html>
You'll have to fine-tune the exact trigger values depending on your document type and the style of your body and #container #base blocks.
There is also the alternative to use a specially crafted script (I can find the url if needed) instead "expression()" rules.
If you explain why you changed those values I could possibly work it out myself.
Thanks
Erdy
Now, to get the correct value of body.width that will trigger the min/max value for the div, you have to compute it.
Something like this:
max value of div: 980
rule between div.width and container.width (in our case body.width): div.width= 0.75 x container.width (0.75 is 75%)
What is the max value of container.width at which point div.width reach its max-width?
div.max-width = 980
container.max = 980/0.75 +/- a fixed number of pixels for borders margins and paddings associated with these elements
div.min-width = 680
container.max = 680/0.75 +/- a fixed number of pixels for borders margins and paddings associated with these elements
You can fine-tune the value of the "fixed number of pixels" by changing the size of the window and seeing if the change in the width of the div is continuous, or if at one point it jumps to its min/max value.