Click to See Complete Forum and Search --> : [RESOLVED] width 100% div background


Kyleva2204
06-25-2007, 06:12 PM
So I have a DIV thats set to be the top bar. I have set it to have a repeating background on the X axis. However when it overflows off the screen, and you scroll to see the rest of the top bar. It display just White.

Any ideas?

#top {height: 64px; width: 100%; background-image: url('http://localhost/commune2/templates/main/images/top_bg.png'); position: absolute; top:0px; left: 0px; background-repeat: repeat-x;}

I have uploaded an image as an attachment so u can see what I mean.

WebJoel
06-25-2007, 06:26 PM
Is the URL correct? I can't seem to find the image.

I shortened your code to:

#top {height: 64px; width: 100%; background: #000 url('http://localhost/commune2/templates/main/images/top_bg.png') repeat-x;}

and added a background-color to assist.

Kyleva2204
06-25-2007, 07:21 PM
..... its a local image. The attached image is what im seeing though.

WebJoel
06-25-2007, 07:28 PM
seeing a screenshot of what you is not helping me. :) I need to test your code using the actual image, to replicate what you are seeing so I can diagnose. :)

Kyleva2204
06-25-2007, 07:32 PM
ive attached the image.

WebJoel
06-25-2007, 09:59 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<title></title>
<style type="text/css">
* {border:0; padding:0; margin:0;}/* Set everything to "zero" */

body {min-height:100%; height:101%;
font:x-small Arial, Verdana, sans-serif;
voice-family: "\"}\"";voice-family:inherit;
font-size:small;/*for IE 5.5 */
} html>body {font-size:small; height:auto;}/* Assist IE6 & <, 100% height */
font-size: small; voice-family: "\"}\"";
voice-family: inherit; font-size: medium;} /* Assist IE rendering height, keyword-font sizes, etc. */

p {font-size: 90%; line-height:1.3em; margin:12px 0 2px 0;}
h1, h2, h3, h4, h5, h6 {font-family: 'times new roman', arial, verdana, serif; background-color:none;
font-style:normal; font-variant:normal; font-weight:normal; margin:14px 0 4px 10px;}
h1{font-size: 1.93em;}
h2{font-size: 1.72em;}
h3{font-size: 1.52em;}
h4{font-size: 1.42em;}
h5{font-size: 1.32em;}
h6{font-size: 1.21em;}
</style>

<style>
#top {height: 64px; width: 100%; background: url('attachment.png') repeat-x;}
</style>

<script type="text/javascript"><!--
// -->
</script>
<link rel="shortcut icon" href="favicon.ico"><!-- path to your favicon -->
</head>
<body>

<div id="top">

</div>

</body>
</html> With attached imange, it works for me. I had trouble getting it, -seemed to be *php image(??!!) -Am I doing something wrong here? Maybe it is how WD attaches image to posts... seems to want to be "attachment.php" (IMAGE file).. :confused:

Kyleva2204
06-25-2007, 10:11 PM
it works fine when you load the page.. but say you have another element on the page, and you resize your browser so that that element doesn't all show. So the scrollbars show up. And when you scroll to see the rest of the element, a part of the top bar shows white.

Kyleva2204
06-25-2007, 10:13 PM
http://optimalconnection.net/file.zip

there is a video demonstrating what is going on.

WebJoel
06-26-2007, 09:11 AM
I am unable to view the movie file in the format it arrived as. -It shows as 'unrecognized' and thows an error, but using the code I sent last night I will re-test this today. AFK for most of the day today tough... more like back this evening...

Kyleva2204
06-26-2007, 09:33 AM
use quicktime or VLC. Probably quicktime.

WebJoel
06-26-2007, 12:24 PM
use quicktime or VLC. Probably quicktime. -Have that, -file not recognized means that the file I received was not compatible or corrupt maybe(?).

Anyway, using this, I get it working:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<title></title>
<style type="text/css">
* {border:0; padding:0; margin:0;}/* Set everything to "zero" */

body {min-height:100%; height:101%;
font:x-small Arial, Verdana, sans-serif;
voice-family: "\"}\"";voice-family:inherit;
font-size:small;/*for IE 5.5 */
} html>body {font-size:small; height:auto;}/* Assist IE6 & <, 100% height */
font-size: small; voice-family: "\"}\"";
voice-family: inherit; font-size: medium;} /* Assist IE rendering height, keyword-font sizes, etc. */

p {font-size: 90%; line-height:1.3em; margin:12px 0 2px 0;}
h1, h2, h3, h4, h5, h6 {font-family: 'times new roman', arial, verdana, serif; background-color:none;
font-style:normal; font-variant:normal; font-weight:normal; margin:14px 0 4px 10px;}
h1{font-size: 1.93em;}
h2{font-size: 1.72em;}
h3{font-size: 1.52em;}
h4{font-size: 1.42em;}
h5{font-size: 1.32em;}
h6{font-size: 1.21em;}
</style>

<style>
body {width:100%;}
#top {height: 54px; width:auto; background-image: url('attachment.png')}
#top p {margin:5px 15px 5px 20px; color:white;}
</style>

<script type="text/javascript"><!--
// -->
</script>
<link rel="shortcut icon" href="favicon.ico"><!-- path to your favicon -->
</head>
<body>

<div style="width:100%;">
<div id="top">
<p>This is the DIV with the background-image "attachment.png"</p>
</div>

<div style="width:auto; height:auto; background-color:#ececec; color:black; padding:25px 20px; margin:10px auto 0 auto;">

<p>This is the DIV below the top banner or header DIV</p>
<p>This is the DIV below the top banner or header DIV</p>
<p>This is the DIV below the top banner or header DIV</p>
<p>This is the DIV below the top banner or header DIV</p>
</div>

<div style="width:auto; height:auto; background-color:#898989; color:black; padding:25px 20px; margin:0px auto;">

<p>This is the DIV below the DIV below the top banner or header DIV</p>
<p>This is the DIV below the DIV below the top banner or header DIV</p>
<p>This is the DIV below the DIV below the top banner or header DIV</p>
<p>This is the DIV below the DIV below the top banner or header DIV</p>
</div>

</div>

</body>
</html> I think what's going on is that you're picking up some padding from something, -which is added~to the "width:100%;". Using "width:auto;" takes this into account and the actual width is margins, padding and width of container = "100% of available space". But yes, I was finally able to replicate the problem you showed. :)

Kyleva2204
06-26-2007, 02:40 PM
The source you gave me does not correct the issue. Thanks for a go though. In my layout, there is a predefined block width. The main page text is inside this block. I do not want to use a width:auto, because then the block would look messed up.

I have reuploaded the video with an MPEG4 codec, the other one was Apple Animation. (Maybe just a codec on Macintoshes, dunno). The url is

http://optimalconnection.net/my_file.zip

WebJoel
06-26-2007, 04:37 PM
The source you gave me does not correct the issue. Thanks for a go though. In my layout, there is a predefined block width. The main page text is inside this block. I do not want to use a width:auto, because then the block would look messed up. I guess I don't follow... if this is the case, you "width:auto;" the contents or percentage them with paddings/margins.

I'd need to see not only the #top but it, -populated with your content-, to know what you're after here. :o Every scenario where I'd use a DIV that way, works. :confused:

I have reuploaded the video with an MPEG4 codec, the other one was Apple Animation. (Maybe just a codec on Macintoshes, dunno). The url is... Still doesn't work for me. I have QT and a quarter-dozen other 'video player' options... this still won't open for me and is identified as 'uindentified format' and offers to 'seek the web for the appropriate player' (which I decline).

Kyleva2204
06-26-2007, 04:52 PM
<html>
<head>
<title>Commune : Test</title>
<style>
body {margin: 0px; background-image: url('background.png'); background-position: center; background-repeat: repeat-y;}

#top {height: 64px; width: 100%; background-image: url('top_bg.png'); position: absolute; top:0px; left: 0px; background-repeat: repeat-x;}

#top #logo {height:64px; width: 207px; position: absolute; top: 0px; left: 20px; background-image: url('logo.png');}

#top #menu {position: absolute; left: 200px; bottom: 0px;}

#top #menu li {float: left; display: block; margin-right: 10px; height: 15px; width: 100px; background: #6F6F6F; text-align: center; font-family: geneva;}
#top #menu li a:link, #top #menu li a:visited {text-decoration:none; font-size: 12px; color: #FFFFFF;}
#top #menu li:hover {background: #B8B8B8;}

#top #menu ul {width: 500px;}

#body {margin-left: auto; margin-right: auto; width:831px; position: relative; top: 80px;}

#text { margin-left: auto; margin-right: auto; width: 800px;}

h1 {font-family: Verdana; color: #303030; margin-bottom: 1px;}
h3 {font-family: Verdana; color: #484848; margin-top: 1px; margin-left: 14px; text-decoration: underline;}
h4 {font-family: Verdana; color: #303030; font-size:20px; text-decoration: underline;}

#main_text {font-family: Arial; color: #000000; font-size: 12px; margin-left: 40px; margin-right: 40px;}
#main_text a:link, #main_text a:visited, #main_text a:active {color: #B61C00; text-decoration:none;}
#main_text a:hover {text-decoration:underline;}
#bulletins {width:400px;}

.image_form {width:300px; height: 50px; border: dashed 1px #757575; margin-bottom: 10px; padding:5px;}
.image_form h1 {float:left; font-size: 20px; font-family: Verdana; color: #303030; margin-top:12px; margin-right:10px;}
.bulletin {border: solid 1px #757575; border-bottom: dashed 1px #757575; margin-bottom: 10px; padding:5px;}
.bulletin b {font-size:15px; color:#303030;}
.alert {width: 500px; padding: 20px; background: #FFEEB5; border: solid 2px #C60700; font-family: Arial; margin-bottom: 20px; font-size: 13px;}
.praise {width: 500px; padding: 20px; background: #d5ebc9; border: solid 2px #559135; font-family: Arial; margin-bottom: 20px; font-size: 13px;}
.overlay {display:none;}

td {font-size: 12px;}
</style>
</head>
<body>

<div id="top">
<div id="logo">&nbsp;</div>
<div id="menu">
@menu
</div>
</div>
<div id="body">
<div id="text">
<h3>Test</h3>
<div id="main_text">

See?
</div>
</div>
</div>
</body>


That is all my source. I have attached all following files for it. Set your browser where your scroll bars appear. Scroll to the right a bit, and look at the top div. the part that was hidden, is grey.

Thanks

WebJoel
06-26-2007, 05:04 PM
#body {margin-left: auto; margin-right: auto; width:831px; position: relative; top: 80px;} You really should use 'reserved words' (body, html, table, etc) for DIV names. This complicates things greatly. :o
It might work, -but it complicate things as the browser 'knows the word' and has to decide how to treat it... as the "body", or as a division named "body" and share the declarations?

Kyleva2204
06-26-2007, 05:11 PM
lol, Ill keep that in mind. Are u able to reproduce what is going on?

Thanks

Centauri
06-26-2007, 06:15 PM
100% is 100% of the screen, so if the page content is wider than the screen, a 100% width element will not be as wide as other content.

if you DON'T use absolute positioning, then the divs would expand to maximum possible width naturally without specifying any width like 100%. Its the absolute positioning which is your problem

WebJoel
06-26-2007, 07:06 PM
I meant to say "shouldn't", not "should" (shouldn't use 'reserved words' (like "body", "table", etc.) for DIV-names lest they further complicate matters).
Yes, -I was able finally to fully reproduce the problem. -My java-soaked synapsii are not wading-through the fairly straightforward nesting DIVs, but my postulation remains that the width is somehow the sum of the element-width and margins and/or padding. -Something is making this pup fatter than it is supposed to be! :eek: I just can't quite get my head around it. "width:auto;" solves it.
I am not a fan of "position:absolute;" the way you are using it. The only time I ever use "absolute" is to position 'out of the document flow' either inside of a "relative-positioned" DIV or container, -or for some element that is expected to 'move' on some action (like a background-image when on-hover for CSS roll-over effects, etc).

"Position:absolute;" a DIV invites trouble to breakfast.. :(

I'll look at this again and will be following the thread..

Kyleva2204
06-26-2007, 08:38 PM
even without position: absolute; it still produces the problem.

Centauri
06-27-2007, 01:43 AM
Ok, I set this up locally and had a play.

Besides the effect you noted, I also noticed the background also becomes offset under the same conditions due to it being positioned relative to the browser window. I solved that by setting the #body (wich I renamed #wrapper to avoid any problems WebJoel mentioned) to a minimum height of 100% (after also setting html and body height to 100%) and applying the background to that. As such, the absolute positioning of the #top div is appropriate so that it doesn't have any effect on the #wrapper height.

Setting a minimum width of 831px to #top works quite nicely except IE6 doesn't know anything about that. One way of preventing #top from becoming too narrow is to place a fixed width element inside it (for IE that is). Applying some semantics to the #top area provides such an opportunity. Whilst human readers can see the logo is a word, other readers of the site, such as screen readers and search engine spiders, cannot read a graphic. The logo can be best marked up as a <h1> heading text, which can then be styled to display the graphic instead of text, and more importantly here, can be given the fixed width of 831px to prevent #top width collapse in IE.

See if this suits: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<style type="text/css">
<!--
* {
margin: 0;
padding: 0;
}
p {
margin: 10px 0;
}
html, body {
height: 100%;
}
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
#wrapper {
width:831px;
min-height: 100%;
background-image: url(background.png);
background-repeat: repeat-y;
margin: 0 auto;
}
* html #wrapper {
height: 100%;
}
#top {
height: 64px;
background-image: url('top_bg.png');
background-repeat: repeat-x;
position: absolute;
min-width: 831px;
width: 100%;
top: 0px;
left: 0px;
}
#top h1 {
width: 811px;
margin: 0 0 0 20px;
height: 64px;
background-image: url(logo.png);
background-repeat: no-repeat;
font-size: 1px;
text-indent: -1000px;
}
#menu {
position: absolute;
left: 220px;
bottom: 0px;
color: #FFFFFF;
}
#text {
width: 800px;
margin: 0 auto;
padding-top: 64px;
}
h3 {
font-family: Verdana;
color: #484848;
margin-top: 1px;
margin-left: 14px;
text-decoration: underline;
}

#main_text {
color: #000000;
margin: 0 40px;
}
-->
</style>
</head>

<body>
<body>
<div id="top">
<h1>commune</h1>
<div id="menu">
@menu </div>
</div>
<div id="wrapper">

<div id="text">
<h3>Test</h3>
<div id="main_text">
<p>It works now</p>
</div>
</div>
</div>
</body>
</body>
</html>


Note I also stripped out all css that does not relate directly to present content.

Cheers
Graeme

artcase
06-27-2007, 11:46 AM
I looked at your image, it has a Safari type scroll bar. I'm running into this problem too with my page in Safari, herein may be the problem.

My page loads correctly in Firefox, has typical IE6 issues, and (wonder of wonders!) works fine in IE7. Have you checked yours for cross-browser compatibility?

Safari adds a scroll "whitespace" when using the center scroll button on the mouse.

Anyone else have this problem with absolute (100%width/height) pages?

Amy