Re: padding-left, padding-right..
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
|