CSS padding (a different question)
http://65.254.36.178/~deltaxit/padding.php
Ignore that it looks like crap. I have just one specific question for this example. Using the following padding code makes the div go wider than I wanted and forces the page wider too by the same amount as the intended padding.
padding-top: 0px;
padding-left: 20px;
padding-bottom: 4px;
Notice how the left padding works fine and pushes the text within that div over 20px. But it also pushes the red div over to the right by 20px too (plus some extra white space too that I can't explain at all). Why? How do I avoid this? I can't use margin because that adds space on the outside which would move the whole div over to the right by 20px revealing white space on the left side too.
This padding crap happens to me all the time. On fixed width layouts I just subtract the padding amount from the width and it looks fine. But this is a full width example where I can't do that, and it's just time for me to finally figure it out what's going wrong anyway.
help. Thanks.
Abhishek Reddy posted this at 11:25 — 13th November 2004.
He has: 3,348 posts
Joined: Jul 2001
Box model (hack).
Tantek's hack page probably explains it better. Padding and borders add to the total width of a box.
In a relative layout, you could try using a relative padding-width and subtracting that from the main 100%.
Probably a more realistic solution is to nest s. Set a margin for the inner that would be your padding.
Not entirely sure. Try it and post back.
fifeclub posted this at 16:30 — 14th November 2004.
He has: 688 posts
Joined: Feb 2001
Those sound like some good, promising suggestions. I don't have time to test it right now but I'll post back when I get a chance. Thanks.
fifeclub posted this at 16:21 — 15th November 2004.
He has: 688 posts
Joined: Feb 2001
Well I tried padding a nested div didn't work either. But you had the right idea about separating the background from the text, using two different divs. I did that and used absolute positioning to move it right 20px instead of via left padding. Viola. It worked great and it didn't screw up the right side of the page either. Thanks.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.