Current location: Hot Scripts Forums » General Web Coding » CSS » padding error, div within div


padding error, div within div

Reply
  #1 (permalink)  
Old 06-14-07, 05:11 AM
manuleka's Avatar
manuleka manuleka is offline
Newbie Coder
 
Join Date: Sep 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
padding error, div within div

ok i've got a block of div which contains another div within!
its floated to the right of my webpage.... here's the codes

style:
css Code:
  1. div.recent_proj{
  2.     background-color:#b0b0b0;
  3.     width:150px;
  4.     position:relative;
  5.     float:right;
  6.     margin-right:10px;
  7.     margin-left:10px;
  8.     border:1px dashed #606060;
  9.     text-align:center;
  10.     color:#000000;
  11.     font-family:tahoma,verdana,arial;
  12.     font-size:11px;
  13.     font-weight:bold;
  14.     }
  15.  
  16. div.recent_proj div{
  17.     position:relative;
  18.     width:100%;
  19.     margin:auto;
  20.     padding:5px;
  21.     background-color:#e0e0e0;
  22.     }
  23. div.recent_proj div a:link, a:visited{
  24.     color:blue;
  25.     font-weight:normal;
  26.     text-decoration:none;
  27.     }
  28. div.recent_proj div a:hover{
  29.     color:red;
  30.     }

html:
HTML Code:
<div id="r_proj" class="recent_proj">
	<br />Recent Projects<br /><br />
		<div>
			<a href="">Site Number 1:<br />
			Fill this space up with
			your site by clicking here!</a><br /><br />
			<a href="">Site Number 2:<br />
			Fill this space up with
			your site by clicking here!</a><br /><br />
			<a href="">Site Number 3:<br />
			Fill this space up with
			your site by clicking here!</a><br /><br />
			<a href="">Site Number 4:<br />
			Fill this space up with
			your site by clicking here!</a><br /><br />
		</div>
</div>
now what i get is that the inner div overlaps the outer/parent div when i add in the padding:5px on the div.recent_proj div

why is this happening? i was expecting the child div to only go as far as the 150px width of the parent div unless i insert picture or something wider than 150px!

can anyone enlighten me please

Last edited by Nico; 06-14-07 at 05:17 AM. Reason: Please use [highlight=css] and [html] wrappers.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 06-14-07, 10:57 AM
jfulton's Avatar
jfulton jfulton is offline
Community VIP
 
Join Date: Apr 2006
Location: Los Angeles, CA
Posts: 660
Thanks: 0
Thanked 0 Times in 0 Posts
This is how the box model works. Margins, borders, padding, etc. are added to any explicit with, they are not included in the width (unless you are in IE6, which has a broken box model.)

http://www.w3.org/TR/REC-CSS2/box.html
http://en.wikipedia.org/wiki/Interne..._box_model_bug
http://www.w3.org/TR/REC-CSS1-961217#formatting-model
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 06-14-07, 05:15 PM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
Umm, as long as you use a doctype to force IE6 into standard-compliance mode, the "correct" box model is used. In quirks-mode, it falls back to the "buggy" (but more logical) box model found in all previous versions of IE with CSS support.

Or atleast that's what I've experienced, and what the wikipedia article says.
__________________
[W3Schools - learn all about the standards.] [QuirksMode - Browser Quirks] [MS's Online Reference Docs] [DOM in Gecko.]
Please pay attention to stickys, announcements and forum rules, thank you.
Please also remember Code Wrappers and [SOLVED] Marking, this helps everyone.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 06-14-07, 11:52 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
This problem seems to appear in Firefox but not IE6.
__________________
Jerry Broughton
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 06-14-07, 11:57 PM
jfulton's Avatar
jfulton jfulton is offline
Community VIP
 
Join Date: Apr 2006
Location: Los Angeles, CA
Posts: 660
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by job0107 View Post
This problem seems to appear in Firefox but not IE6.
It's not a problem - it's the expected behavior. Firefox is doing things correctly - IE6 is the one which is wrong. If you define something as 100% width and 10px of padding all around, then the total outer width of the container is 10px (left side) + N + 10px (right side) where N is the width of the parent container.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 06-14-07, 11:58 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Remove the width:100%; and everything will work as expected.

CSS Code:
  1. div.recent_proj div{
  2.     position:relative;
  3.     margin:auto;
  4.     padding:5px;
  5.     background-color:#e0e0e0;
  6.     }

If you do not specify a width for a <div> it will automatically span the width of it's container.


Now try padding:15px; and see what happens.
__________________
Jerry Broughton

Last edited by job0107; 06-15-07 at 12:27 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
css help (very simple i think) jcoxy4 CSS 2 06-11-07 03:32 PM
Dumb HTMl Problem [Could be CSS] _net HTML/XHTML/XML 7 05-25-07 05:51 AM
CSS Rollover Problem in IE tjs CSS 4 08-30-06 12:29 PM
Can't Understand java script maverickminds JavaScript 1 07-16-06 02:23 PM
div positioning the_mole001 CSS 5 09-25-05 06:56 PM


All times are GMT -5. The time now is 06:55 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.