|
Starhugger -> RE: Div inner margin (2/26/2007 2:24:36)
|
Thanks for replying, Jurgen. Unfortunately, putting either "padding" or "margin" on also increases the Div area size. I'm attaching a screenshot as an example, plus the code I'm using: div#homecontainer {
width: 760px;
vertical-align: top;
background-color: lightblue;
}
div#welcome {
clear: both;
width: 760px; height: 100px;
padding-top: 15px; padding-left: 15px;
padding-right: 15px; padding-bottom: 15px;
margin-top: 15px; margin-left: 15px;
margin-right: 15px; margin-bottom: 15px;
background-color: grey;
border: solid black 2px;
}
div#welcome h1 {
font-size: 135%;
font-weight: bold;
font-style: italic;
font-family: verdana,arial,sans-serif;
text-align: center;
color: darkgreen;
margin-top: 0;
margin-bottom: 0px;
background-color: pink;
}
<div id="homecontainer">
<div id="welcome">
<h1>Test text</h1>
</div>
</div> I've colour-coded the different parts so you can see what each is doing. The text has a pink background. The Div surrounding the text has a grey background and a black border. And the Div surrounding that Div has a blue background. In the screenshot that "margin" pushes the grey Div out (surrounded by the black border), and "padding" pushes it out past the border (but doesn't take the Div's background colour with it). The fact that it overhangs the right edge shows how both attributes add to the Div area. So I'm still stuck recalculating the full area by figuring the content area and then adding the padding or margin to it. I was hoping there might be a way to avoid that. It's much easier to use tables for everything. I'm trying to break myself of the habit. Guess I've been spoiled. SH
|
|
|
|