Padding property problem in nested <div>s

This is a discussion on "Padding property problem in nested <div>s" within the Web Page Design section. This forum, and the thread "Padding property problem in nested <div>s are both part of the Design Your Website category.



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Design Your Website > Web Page Design

Notices


Reply
 
LinkBack Thread Tools
  #1  
Old Apr 8th, 2006, 09:30
New Member
Join Date: Apr 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Padding property problem in nested <div>s

Hi everybody!

I'm trying to wrap my head around some strange bahaviour I'm experiencing with CSS - in particular the padding property - and was wondering if anyone would be kind enough to help me shed some light on it.

Here goes:

I have a XHTML page that consists of a series of <div>s that are styled by a CSS stylesheet, that specifies the width and height of the <div> tags. The <div> tags now sit next to one another perfectly, and there is no unwanted space between the <divs>s (that's a problem I was experiencing earlier).

Anyhow, my problem is this, for example, one <div> has an id of "logo" and is styled in the CSS stylesheet like this:

Code: Select all
#logo
{
  width: 304px;
  height:289px;
  float:left;
}
There is a background image in a wrapper <div>, that this <div> sits on top of. In order to fit in with this background, I need to insert content into this logo <div> 26px across. When I insert padding-left:26px, instead of simply starting the content 26px across and preserving the width and height property values, the div instead grows by 26px, causing all the other <div>s then lose their allignment. The solution seems to be to subtract 26px off the width value as shown here.

Code: Select all
#logo
{
  width:278px;
  height:289px;
  float:left;
  padding-left: 26px
}
Is there an easier way to specify where content should be placed within a <div> without having to alter the width properties, or is the solution indicated here the best practice?

Many thanks in advance for any help or feedback.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Apr 8th, 2006, 15:45
herkalees's Avatar
Highly Reputable Member
Join Date: Jul 2005
Location: Massachusetts, USA
Age: 87
Posts: 576
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Padding property problem in nested <div>s

Actually, you've come up with the exact fix for your problem, and as far as I know, there isn't another way. It's quite normal actually.

Adding padding to either side of a <div> will in fact increase the <div>s width by that amount. The solution (the correct and only solution) is to simply decrease the {width:XXXpx} by that same amount.

You're learning fast.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Apr 8th, 2006, 16:00
New Member
Join Date: Apr 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Padding property problem in nested <div>s

Hey kerkalees.

Thanks a lot for the reply.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
padding, property, problem, nested, ltdivgts

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with xml-flash and loading movie property mars Flash & Multimedia Forum 8 Apr 11th, 2008 17:41
CSS margin-bottom property problem cangoalie Web Page Design 12 Mar 8th, 2008 20:40
ie padding problem adsalamon Web Page Design 1 Dec 29th, 2006 16:31
IE 7 problem - double padding? edd_jedi Web Page Design 2 Nov 21st, 2006 15:31
Please help - position problem with nested divs DavidinLondon Web Page Design 1 May 21st, 2006 15:10


All times are GMT. The time now is 21:34.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42