width problem with div

liunx

Guest
Hi,<br />
<br />
Problem description: top div is not taking the whole width of the window but something smaller than that.<br />
<br />
Playing with the code and searching for info, I think that I was able to understand what the problem is but could not figure out a fix. <br />
<br />
Take a look at the first two lines (body and top). the width percentage used in "top" is based on the width of the parent object. I think the parent object of the top section is the body. because of using left and right margins for the body, the body width is smaller than that of the window.<br />
<br />
I need a different way to specify the width of top or be able to do somehing like width=100% + 185px !!!!<br />
<br />
Thanks,<br />
Sam<br />
<br />
----- code: just take a look at the first two lines -----<br />
<br />
body {margin-right: 85px; margin-left: 100px; margin-top: 130px}<br />
#top {position: absolute; top: 0px; left: 0px; height: 130px; width: 100%}<br />
#nav {position: absolute; top: 140px; right: 0px; width: 85px}<br />
#lef {position: absolute; top: 140px; left: 0px; width: 100px}<br />
#footer {position: relative; top: 0%; left: 0%; width: 100%}<br />
<br />
(and in the body section)<br />
<br />
<body><br />
<!-- Main contents of page --><br />
<br />
<div id="top" align=center><br />
<!-- header contents --><br />
</div><br />
<br />
rest of code<!--content-->my guess would be that you're going to have to put in another section (call it main maybe) and then put the majority of your code in there. Then you can have your "top" at the right width, and just have to put in an extra div for the main text.<br />
<br />
Sounds like the easiest and quickest way round it to me...<br />
<br />
<br />
body {margin: 0px}<br />
.main {position: absolute; margin: 130px 85px 0px 100px} <br />
.top {position: absolute; top: 0px; left: 0px; height: 130px; width: 100%} <br />
.nav {position: absolute; top: 140px; right: 0px; width: 85px} <br />
.left {position: absolute; top: 140px; left: 0px; width: 100px} <br />
.footer {position: relative; top: 0%; left: 0%; width: 100%} <br />
<br />
<body> <br />
<div class="main"><br />
<!-- Main contents of page --> <br />
</div><br />
<div class="top" align=center> <br />
<!-- header contents --> <br />
</div><!--content-->Thanks jpmoriarty and Dave. <br />
<br />
The expression works well if I subtract 24 pixels like this:<br />
width: expression(document.body.offsetWidth-24)<br />
Things will perfectly fit even if the window is resized or screen resolution is changed. Without subtracting the 24 pixles there will always be a horisantal scroll bar for 24 pixles. Sure I have no clue why there was a need to subtract the 24 pixles but with that it works well (I only tested on my computer).<br />
<br />
Regarding the main idea I tried it but continude to have some problems that I will try to resolve later today.<br />
<br />
I am very sleepy and going to sleep<br />
<br />
Thanks again,<br />
Salam<!--content-->Hi Dave or who ever may know the answer,<br />
<br />
Do you know of a formula to calculate the hight of the contents of a division kind of similar to the formula you gave me earlier in this thread:<br />
width: expression(document.body.offsetWidth)<br />
<br />
The reason why I need it is that the default height of a division matches the height of its contents unless if the height is set. Background color of the division applies to the height of the division. I have a left and right divisoins and I like thier background colors to be of the same height. If I can calculate the heights of thier contents then I can set the height of the shorter one to match the height of the other and thus the background colors of both will cover the same hight.<br />
<br />
If I receive no answer I will open a new thread for the question.<br />
<br />
Thanks<br />
Salam<!--content-->What do you mean by "top div is not taking the whole width of the window"? width: 100% will make it take the entire width.<br />
<br />
Regarding your second question: you want left and right cols to span the entire height of the main contents, right? Well, actually, they won't. But you can create that effect.<br />
<br />
Have one gif:<br />
****==============<br />
where **** is bgcolor of left, and ==== of main contents.<br />
Have another gif to have background color of right col, width or the right col and any height (5px, maybe)<br />
<br />
body {margin-top: 130px; background: url('rightbg.gif') repeat-y top right} /* This will give background to the right col */<br />
#top {position: absolute; top: 0px; left: 0px; height: 130px; width: 100%} /* Positioning the top box (nothing changes) */<br />
#nav {position: absolute; top: 140px; right: 0px; width: 85px} /* Positioning the right col */<br />
#mainboth {margin-right: 85px; background: url('left_and_mainbg.gif') repeat-y top right;} /* This will contain both main and left contents */<br />
#main {margin-left: 100px} /* Main contents with left margin to allow left div to display */<br />
#lef {float: left; width: 100px} /* Note that left div is NOT absolute positioned, but floated within mainboth div, to the left of main */ <br />
#footer {position: relative; bottom: 0; margin-bottom: 0; width: 100%; background: #ffffff;} /* background required to stop the "stretching" of body backgrounds */<br />
<br />
#top {text-algin:center; margin: 0 auto;} /* Added later for centering top div */<br />
<br />
Now the fun begins<br />
<br />
<body> <br />
<div id="mainboth"><br />
<div id="lef"><!-- Left --></div><br />
<div id="main"><!-- Main contents of page --> </div><br />
</div><br />
<div id="top"><br />
<!-- header contents --> <br />
</div> <br />
<div id="nav"><br />
<!-- Right Nav --><br />
</div><br />
<div id="footer"><br />
<!-- Footer --><br />
</div><br />
</body><br />
<br />
Again, try working things around. Note that with floats, left div NEEDS to come before main page contents. Hope this helps. Hope you stay away from tables. Hope you dont need to learn javascript to do positioning and styles :)<br />
And finally, hope not many civilian lives are lost in Iraq.<!--content-->
 
Back
Top