Connecting Tech Pros Worldwide Help | Site Map

div css control

TheServant's Avatar
Expert
 
Join Date: Feb 2008
Location: Australia
Posts: 913
#1: Feb 9 '09
I am trying to re-do everything on my site so it is all neat and organized code, which includes re-doing my css. I have realized a problem that can be overcome in other ways but it would be easier if I could do it here.
Here is some of my css:
Expand|Select|Wrap|Line Numbers
  1. body {
  2.     font: 12px Verdana, Arial, Helvetica, sans-serif;
  3.     background: #000000 url(top_bg.png) repeat-x;
  4.     height: 100%;
  5.     width: 1024px;
  6.     margin: 0 auto;
  7.     padding: 0;
  8.     behavior: url("../csshover3.htc");
  9. }
  10.         #header {
  11.             width: 100%;
  12.             margin: 0;
  13.             padding: 0;
  14.             background: silver;
  15.             text-align: center;
  16.         }
  17.         #content_wrapper {
  18.             height: 100%;
  19.             width: 1000px;
  20.             margin: 20px 0;
  21.             padding: 10px;
  22.             border: gray groove 2px;
  23.             background: silver;
  24.             display: block;
  25.             overflow: hidden;
  26.         }
  27.                 #left_menu {
  28.                     height: 100%;
  29.                     width: 150px;
  30.                     float: left;
  31.                     padding: 5px;
  32.                     border: black groove 2px;
  33.                 }
  34.                 #content {
  35.                     width: 668px;
  36.                     float: left;
  37.                     padding: 0;
  38.                     border: black groove 2px;
  39.                 }            
  40.         #footer {
  41.             width: 1000px;
  42.             margin: 0;
  43.             padding: 5px 12px;
  44.             background: silver;
  45.         }
Firstly, my div's (#left_menu and #content) are not 100% height. Everywhere just says make sure the body and parent div is height 100% and all is good, however this is not working in my case.

Second, I have noticed a very annoying problem which is if I have padding / borders / margins and use width 100% / height 100% it simply adds it on to the body width / height. Let me explain: The body is 1024px. If I have the #header width as 100% it works fine. If I add a 2px border it is 1028px wide (100% + 4px). Is there a way to have the 100% include the 2px, or do you have to do nested div statements?

Thanks for your help.
drhowarddrfine's Avatar
Expert
 
Join Date: Sep 2006
Posts: 5,561
#2: Feb 9 '09

re: div css control


So body is 100% of what? You need to set html to 100%, also.

'width' is the width of the content. Borders, margin and padding are outside the width.
TheServant's Avatar
Expert
 
Join Date: Feb 2008
Location: Australia
Posts: 913
#3: Feb 9 '09

re: div css control


OK, so there is no easy way to have one width for the body, or html, and the rest is done automatically when the rest includes borders, padding and margins?

And just a quick note: The editor I am using (phpDesigner) doesn't recognise html as a css class like it does body? Is html a normal class to define? And besides using minheight (I can never get it to work in IE) can something else be done to height to use it like that?
drhowarddrfine's Avatar
Expert
 
Join Date: Sep 2006
Posts: 5,561
#4: Feb 9 '09

re: div css control


I just set html,body{height:100%} in my css. Originally, IE would not allow setting styles on <html> but I think that's fixed in IE7.

Up through IE6, min-height did not work and IE treated height as min-height. But that's IE for you. IE7 still screws it up when it's combined with height.

Google for Diaz min-height hack.
TheServant's Avatar
Expert
 
Join Date: Feb 2008
Location: Australia
Posts: 913
#5: Feb 10 '09

re: div css control


Thanks for your help, I will have a look.
TheServant's Avatar
Expert
 
Join Date: Feb 2008
Location: Australia
Posts: 913
#6: Feb 10 '09

re: div css control


Hey, been working on this but it’s constantly got issues:
Expand|Select|Wrap|Line Numbers
  1.  html,body {
  2.     min-height: 500px;
  3.     height: auto !important;
  4.     height: 100px;
  5.     width: 1024px;
  6.     margin: 0 auto;
  7.     padding: 0;
  8. }
  9.         #content_wrapper {
  10.             height: 100%;
  11.             width: 1000px;
  12.             margin: 10px 0;
  13.             padding: 10px;
  14.             border: gray groove 2px;
  15.             background: silver url(content_bg_dark.gif) repeat;
  16.             display: block;
  17.         }
  18.                 #left_menu {
  19.                     height: 100%;
  20.                     width: 150px;
  21.                     float: left;
  22.                     padding: 10px 5px;
  23.                     border: gray groove 2px;
  24.                     text-align: center;
  25.                     background: silver url(menu_bg.png) repeat-y;
  26.                 }
  27.                 #content {
  28.                     height: 100%;
  29.                     width: 648px;
  30.                     float: left;
  31.                     padding: 10px;
  32.                     border: gray groove 2px;
  33.                     background: silver url(content_bg.gif) repeat;
  34.                 }
  35.                         #news_bar {
  36.                             width: 618px;
  37.                             border: gray groove 2px;
  38.                             background: black;
  39.                             color: red;
  40.                             padding: 0 10px;
  41.                             margin: 0 auto;
  42.                             text-align: center;
  43.                         }
  44.                         #inner_content {
  45.                             width: 618px;
  46.                             margin: 10px 0 auto;
  47.                             padding: 5px;
  48.                             text-align: left;
  49.                         }
  50.                 #right_menu {
  51.                     height: 100%;
  52.                     width: 150px;
  53.                     float: right;
  54.                     padding: 10px 5px;
  55.                     border: gray groove 2px;
  56.                     text-align: center;
  57.                     background: silver url(menu_bg.png) repeat-y;
  58.                 }
  59.  
The page is as follows:
Expand|Select|Wrap|Line Numbers
  1. <body>
  2.     <div id="content_wrapper">
  3.         <div id="left_menu">
  4.             <p>Left Menu</p>
  5.         </div>
  6.         <div id="content">
  7.             <div id="news_bar">
  8.                 <p>News Bar</p>
  9.             </div>
  10.             <div id="inner_content">
  11.                 <p>Inner Content<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />This is a word.</p>
  12.             </div>
  13.         </div>
  14.         <div id="right_menu">
  15.             <p>Right Menu</p>
  16.         </div>
  17.     </div>    
  18. </body>
  19.  
Now the problem is: The height fix works very well, provided that the height of the contents (for example #inner_content) does not exceed the height specified in the body definition at the top (100px). If it does, the left and right menu do not size along with the #content, and #content just gets bigger while #left and #right menu stay the same height as the parent definition (100% = 100px) which is what I have told it to do.

Is there a way to have them resize along with the rest of the contents (ie. #content)?
drhowarddrfine's Avatar
Expert
 
Join Date: Sep 2006
Posts: 5,561
#7: Feb 10 '09

re: div css control


Does all that height stuff have to be in there for any reason? I took it all out and just added 'height:100%'.
TheServant's Avatar
Expert
 
Join Date: Feb 2008
Location: Australia
Posts: 913
#8: Feb 10 '09

re: div css control


If you're talking about the body tag then yes. That was Diaz's fix. When I get home I will check it on all browsers to see if it can be just height: 100%;

And if you mean individual tags, then yes the height value must be passed on between parents otherwise it will be defaulted to auto I think and lose the body height. Is my question clear?
TheServant's Avatar
Expert
 
Join Date: Feb 2008
Location: Australia
Posts: 913
#9: Feb 10 '09

re: div css control


Just height 100% works fine on all browsers, but I haven't tried IE6. So does anyone have a suggestion as to how I could solve my problem?
Expert
 
Join Date: Aug 2008
Posts: 397
#10: Feb 10 '09

re: div css control


You could help solve our problem by putting your page on your server and pointing to it in your post. Trying to guess what you want based on markup and confused CSS is a waste of everyone's time, imo.

Notes on the file. Tested in compliant browsers and IE 6/7. If it ain't what you want, tell us what needs to change.

Please see:
http://www.chelseacreekstudio.com/ca/cssd/test-108.html
TheServant's Avatar
Expert
 
Join Date: Feb 2008
Location: Australia
Posts: 913
#11: Feb 11 '09

re: div css control


Sure: My site.
The problem is, I have 3 columns in the middle div and they are not all the same height. I want them all the same height.
If there are any PHP errors, ignore them, this is the test site, so just look at the layout and CSS.
Expert
 
Join Date: Aug 2008
Posts: 397
#12: Feb 11 '09

re: div css control


Read the article and follow the three column tutorial on this page (faux columns created using a repeating image):
http://www.alistapart.com/articles/negativemargins
Or try the "equal height columns" method (using only CSS to create equal height column), here:
http://www.positioniseverything.net/...onetruelayout/
Or boggle your mind and see the "companion column method," here:
http://www.satzansatz.de/cssd/companions.html
TheServant's Avatar
Expert
 
Join Date: Feb 2008
Location: Australia
Posts: 913
#13: Feb 11 '09

re: div css control


Thanks for your help mate, I will read up and come back if I have any more questions.
drhowarddrfine's Avatar
Expert
 
Join Date: Sep 2006
Posts: 5,561
#14: Feb 11 '09

re: div css control


I don't understand. You said just height 100% fixed the problem. In the site you linked to, you didn't add height:100% to html.
TheServant's Avatar
Expert
 
Join Date: Feb 2008
Location: Australia
Posts: 913
#15: Feb 13 '09

re: div css control


If i change the html tag to 100% all it does is get my screen size and make my page that big. I want a dynamic one, however I think that because the middle content divs which I would like to be made the same height are not working because they are floating. I did not find that those previous articles answered my problem, but it was interesting anyway.
Reply