Forum Moderators: not2easy
If I do it with a table with 100% width it works fine - but I want to do this with CSS.
So - how do you set width to 100% on a div within a div even if there is horizontal scrolling.
Note: on this site I can't avoid horizontal scrolling on a small screen.
I suggest creating a 100% DIV with margin and padding set to 0px. Then, inside that div, place the "real" DIV with the desired padding etc.
Another thing that might work (depending on the rest of your page) is not specifying a width at all, thus only needing a single DIV. It should automatically expand to be 100%, minus padding ...
kapow: is your main content a fixed width? If so you could specify your header div width to be the same.
So, when is it one or the other?
Well, if your page is 1000px wide, but your window is 800px wide - then 100% will be 800px. If the content of the div expands, the background still won't.
If your div resides inside another fixed width container, whose width is less than the width of the browser window - then 100% will only expand to the width of the outer div.
> I think he is saying that his main content is wider than the window... and it disappears off the right-hand side so he'd like his header div to do likewise so that it doesn't appear to stop when you scroll the page..
Yep, thats the problem.
> kapow: is your main content a fixed width?
Not quite. Below the header div is a table. The table is 100% width - it expands to fill the remaining screen (on a large screen), but the header div doesn't. The table has 4 columns, each column has a pic at the top 150px wide. The left nav is 225px wide (a div). The site is for an interior-designer so it has lots of pictures, and the designer really wants those 4 columns. I could re-design the whole thing but there are about 100 pages. I would really like to know if there is a nice simple thing I can do to my CSS-header-div without having to manually redo all of the pages.
> If the content of the div expands, the background still won't.
Are you saying this can't be done with divs?
> If the content of the div expands, the background still won't.
Are you saying this can't be done with divs?
Does the problem occur only on smaller screens when there's horizontal scrolling, or all the time?
which is why I tend to agree with grahamstewart on this one, although I wouldn't do it with a "colspan=4" row I'd do it with a caption as this is exactly what the caption to a table is for, giving it a heading:
example:
<table border="1" width="900px">
<caption id="header">headertext</caption>
<tr><td>cell l</td><td>cell 2</td><td>cell l</td><td>cell 2</td></tr>
<tr><td>cell l</td><td>cell 4</td><td>cell l</td><td>cell 2</td></tr>
</table>
then you can format the caption with CSS the same as it was in the div hopefully
Suzy
<div id="header" style="border: 1px dashed red">
Header
</div>
<div id="content" style="border: 1px dashed green">
<img width="2000" height="5" src="graphic.gif">
</div>
Place this on a page and view it. You should see that content div extends off the side of the window (if not you have a mighty big screen..make the window smaller) and causes a horizontal scrollbar to be displayed. Now if you scroll to the right you will see that the header div is only as wide as the window, not the full width of the content.
So the question is how do you specify the header so that it is as wide as the content?
<div id="header" style="border: 1px dashed red">
Header
<div id="content" style="border: 1px dashed green">
<img width="2000" height="5" src="graphic.gif">
</div>
</div>
Works for my simplified example at least. Does that help?
If not then I suggest you download a decent text editor that supports regular expressions and multi-document search-replace (Textpad is good) and make your changes with that. At least that will save you "several days work". :)
The text in the header is white and the header background is a dark colour, the text in the content div is a dark colour and the background is a light colour. This is done with the CSS.
So if I wrap the header div around the content div the content div colours get messed up.
Also I have set the header to 150px high in the CSS with a 50px top margin, that wouldn't work if the content were inside the header.
I'm stuck arnt I :(
I think its major edit time. Any last suggestions?
I use DreamWeaver, it has great search and replace functions but all of the headers have different content ie each has an h1,h2 and h3 and a link.
#header {
color: black;
background: white;
}
#header #content {
color: white;
background: black;
}
The top-margin;50px should still work fine, but do you really need to specify that height?