Reply
Problem with CSS Layout
Old 05-21-2005, 06:38 AM Problem with CSS Layout
danburzo's Avatar
Skilled Talker

Posts: 82
Location: Bistrita RO
I have some nested divs:

Code:
<body>
<div id="page">
   
   <div id="main">
      <div id="content">...</div>
      <div id="right">...</div>
   </div>

</div>
<div id="footer">...</div>
</body>

to which i've applied the styles:


Code:
body {
   text-align: center;
   background: #2E2E2E;
   margin: 0;
   padding: 0;
}

#page {
   width: 750px;
   margin: 0px auto;
   text-align: left;
   background: #FFFFFF;
   }

#main {
   width: 750px;
   background: #FFFFFF;
}

#content {
   width: 510px;
   float: left;
   padding-left: 20px;
   padding-right: 20px;
   padding-top: 20px;
   padding-bottom: 20px;
   background: #FFFFFF;
}

#right {
   width: 159px;
   float: left;
   color: #C03400;
   border-left: 1px dotted #333333;
   padding:20px;
   background: #FFFFFF;
   }

notice that the background color of the page is a dark grey. I want the whole "main" div to have a white background. I've set background:#ffffff, as you see, but it only works in IE.

How can i make it work in Firefox?
danburzo is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 05-21-2005, 08:53 AM
chrishirst's Avatar
Super Moderator

Posts: 13,519
Location: Blackpool. UK
background-color is what you need
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-22-2005, 02:41 AM
danburzo's Avatar
Skilled Talker

Posts: 82
Location: Bistrita RO
Still not working... I mean this isn't the problem, here are some screenshots of what my page looks like in IE and FF:

Firefox:


IE:


I want the page to look somehow like in IE... i mean the whole #main div to have a white background. I think the problem is about the two divs , #content and #right being floats.
danburzo is offline
Reply With Quote
View Public Profile
 
Old 05-22-2005, 03:55 AM
chrishirst's Avatar
Super Moderator

Posts: 13,519
Location: Blackpool. UK
Your divs aren't nested properly for content and right to affect each other. IE gets it wrong by standards, though it does work as you would expect it to logically and sets child divs without a explicit height to 100% of the parent container though to standards it should be to the contents of the child.

A few small mods gets this

http://www.candsdesign.co.uk/demo/danburzo/

HTML Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
body {
   text-align: center;
   background: #2E2E2E;
   margin: 0px;
   padding: 0px;
}

#page {
   width: 750px;
   margin: 0px auto;
   text-align: left;
   background: #FFFFFF;
   }

#main {
   width: 750px;
   background: #FFFFFF;
}

#content {
   float: left;
   padding: 20px 0px 20px 20px;
   background: #FFFFFF;
}

#right {
   width: 159px;
   float: right;
   color: #C03400;
   border-left: 1px dotted #333333;
   padding:0px 20px 20px 20px;
   background: #FFFFFF;
   margin:0px 0px 0px 20px;
   }
#footer {
   position:relative;
   text-align:center;
   clear:both;
   color:#FF0000;
   background-color:#FFFFFF;
}
</style>
</head>

<body>
<div id="page">
   
   <div id="main">
      <div id="content">
Content
	  <div id="right">
Right Side
	  </div> <!-- right -->

      </div> <!-- content -->
   </div> <!-- main -->

<div id="footer">Footer</div>
</div> <!-- page -->

</body>
</html>
Note: if the content in "content" extends below the right side it will wrap around the right side.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System

Last edited by chrishirst : 05-22-2005 at 03:58 AM.
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-22-2005, 03:56 AM
OmuCuSucu's Avatar
Vi Veri Veniversum Vivus

Posts: 1,167
Name: Dragos-Valentin
Location: Cluj-Napoca, RO
hmmmm ....

i remember having problems with exactly that same thing before.

though i remember solving it in a really odd way LOL.

go with chrishirst
__________________
.
» Please remember to add to my Talkupation if you enjoyed my post. Thank you :)
.

Last edited by OmuCuSucu : 05-22-2005 at 04:00 AM.
OmuCuSucu is offline
Reply With Quote
View Public Profile
 
Old 05-22-2005, 05:13 AM
Novice Talker

Posts: 6
The "content" div is automatically extending to hold it's content. If you set a height value to "content" and "main" of say 100% the background color will extend equally all the way down the page.

In other ways, the background color changes because the "content" div is stopping just below the text.
shaber is offline
Reply With Quote
View Public Profile
 
Old 05-22-2005, 05:55 AM
danburzo's Avatar
Skilled Talker

Posts: 82
Location: Bistrita RO
Wow, thanks for the replies.

I found another solution: how about clearing the floats:

Code:
<body>
<div id="page">
   
   <div id="main">
      <div id="content">...</div>
      <div id="right">...</div>
      <div style="clear:both">&nbsp</div>
   </div>

</div>
<div id="footer">...</div>
</body>
seems to work as well.
danburzo is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Problem with CSS Layout
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.15653 seconds with 12 queries