|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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.. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
dorayme wrote:
> In article <47f15341$1@news.x-privat.org>, maya <maya778899@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 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! And that is one of the keys, although, oddly current FireFox seems to use the standards mode box type with the transitional doctype. What happens is the standards mode box model which is usually triggered by strict doctypes, considers the width to be the width of the contents, not the width of the box. The old box model had the width as the width of the container, including margins and borders. So you can do what Dorayme has done and set the width of the container and nest another container inside that has the padding and border set. There's a bit more on this on a post of mine on the 24th titled Standard Module Format. Dorayme is just a good bit ahead of me! Jeff > |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
dorayme wrote:
> In article > <doraymeRidThis-95AA2C.15362801042008@news-vip.optusnet.com.au>, > dorayme <doraymeRidThis@optusnet.com.au> wrote: > >> 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... |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
dorayme wrote:
> In article > <doraymeRidThis-95AA2C.15362801042008@news-vip.optusnet.com.au>, > dorayme <doraymeRidThis@optusnet.com.au> wrote: > >> 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 > |
|
![]() |
| Outils de la discussion | |
|
|