By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,932 Members | 1,454 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,932 IT Pros & Developers. It's quick & easy.

padding-left, padding-right..

P: n/a
hi,

I recently discovered the hard way that when you had padding-right or
padding-left to a div it increases the with of the div... how do you
add left-padding or right-padding to a div w/o changing the width of it?

(for example: I have a div that's 320px wide, content inside is 300px
and I added padding-left:10px but it increased with of div to 330px.. I
want width of it to remain 320px but I need a padding on the left of 10px..)

thank you..
Mar 31 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
maya wrote:
hi,

I recently discovered the hard way that when you had padding-right or
padding-left to a div it increases the with of the div... how do you
add left-padding or right-padding to a div w/o changing the width of it?

(for example: I have a div that's 320px wide, content inside is 300px
and I added padding-left:10px but it increased with of div to 330px.. I
want width of it to remain 320px but I need a padding on the left of
10px..)

thank you..

I vaguely recall something from school - I think it was called
"arithmetic" :-)

<div style="width: 300px; padding: 10px"></div>

300 + 2 * 10 = 320
All kidding aside, if for some reason you can't just subtract the
padding from the width of the box (i.e. if you're using different units
for the width and the padding) then you can just add a second box inside
the first, with no defined width and the padding you want:

<div style="width: 60%">
<div style="padding: 2em">
<p>Content</p>
</div>
</div>
Note: inline styles are for easy demonstration purposes. You shouldn't
actually use them.

Jeremy
Mar 31 '08 #2

P: n/a
In article <47********@news.x-privat.org>, maya <ma********@yahoo.com>
wrote:
hi,

I recently discovered the hard way that when you had padding-right or
padding-left to a div it increases the with of the div... how do you
add left-padding or right-padding to a div w/o changing the width of it?

(for example: I have a div that's 320px wide, content inside is 300px
and I added padding-left:10px but it increased with of div to 330px.. I
want width of it to remain 320px but I need a padding on the left of 10px..)

thank you..
Would this example help you:

<http://netweaver.com.au/alt/widthPadding.html>

(the padding left is exaggerated to demonstrate. The url will not be for
the world long.)

--
dorayme
Mar 31 '08 #3

P: n/a
In article <Qs******************************@earthlink.com> ,
Jeff <jeff@spam_me_not.comwrote:
dorayme wrote:
In article <47********@news.x-privat.org>, maya <ma********@yahoo.com>
wrote:
hi,

I recently discovered the hard way that when you had padding-right or
padding-left to a div it increases the with of the div... how do you
add left-padding or right-padding to a div w/o changing the width of it?

(for example: I have a div that's 320px wide, content inside is 300px
and I added padding-left:10px but it increased with of div to 330px.. I
want width of it to remain 320px but I need a padding on the left of
10px..)

thank you..
Would this example help you:

<http://netweaver.com.au/alt/widthPadding.html>

(the padding left is exaggerated to demonstrate. The url will not be for
the world long.)


I think it's been a while since Dorayme wrote that, as she would not
use a transitional doc-type now!
Well, "she" (and much more correctly "it") should have been changed by
me to Strict and it - no, not me! the other it, the html doc it - is now
Strict. So thanks Jeff.

I just grab whatever html file is lying around and throw something in it
that is to some current need. On this occasion, I seemed to have grabbed
something old or something used to discuss some difference between
strict and not strict. <g>

--
dorayme
Apr 1 '08 #4

P: n/a
In article
<do**********************************@news-vip.optusnet.com.au>,
dorayme <do************@optusnet.com.auwrote:
Well, "she" (and much more correctly "it") should have been changed by
me to Strict and it - no, not me! the other it, the html doc it - is now
Strict. So thanks Jeff.
should really read

Well, "she" (and much more correctly "it") should have changed it - no,
not me! the other it, the html doc it. It is now Strict. So thanks Jeff.

--
dorayme
Apr 1 '08 #5

P: n/a
dorayme wrote:
In article
<do**********************************@news-vip.optusnet.com.au>,
dorayme <do************@optusnet.com.auwrote:
>Well, "she" (and much more correctly "it") should have been changed by
me to Strict and it - no, not me! the other it, the html doc it - is now
Strict. So thanks Jeff.

should really read

Well, "she" (and much more correctly "it") should have changed it - no,
not me! the other it, the html doc it. It is now Strict. So thanks Jeff.
I see....:) thank you all very much for your responses...
Apr 3 '08 #6

P: n/a
dorayme wrote:
In article
<do**********************************@news-vip.optusnet.com.au>,
dorayme <do************@optusnet.com.auwrote:
>Well, "she" (and much more correctly "it") should have been changed by
me to Strict and it - no, not me! the other it, the html doc it - is now
Strict. So thanks Jeff.

should really read

Well, "she" (and much more correctly "it") should have changed it - no,
not me! the other it, the html doc it. It is now Strict. So thanks Jeff.
Hmm, I don't think we've discussed the gender of html docs before.
Although I can certainly understand the confusion behind what gender a
transitional page is!

Jeff
>
Apr 3 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.