Forum Moderators: not2easy
I've got the following HTML:
<div class="maincontainer"> <div class="mainleft"></div> <div class="mainright"> <div class="header"></div> <div class="content"> <div class="text">
<h1>title</h1><p>text</p>
</div> </div> </div> </div> And the following CSS:
body {
background-color: #7E7E7E;
text-align: center; /* IE fix */
}
.maincontainer {
width: 750px;
background-color: #292929;
margin-left: auto;
margin-right: auto;
height: auto;
text-align: left; /* reset text alignment */
}
.mainleft {
position: relative;
}
.mainright {
position: relative;
left: 210px;
}
.header {
width: 540px;
height: 180px;
background-image: url('../images/header_bg.jpg');
background-repeat: no-repeat;
background-position: bottom left;
}
.content {
font-family: Arial;
width: 540px;
height: auto;
background-color: #525252;
}
.text {
background-color: #fff;
}
In IE, all works well, but in FF (1.5.0.1) the content DIV is being pushed down by the H1 tag... As soon as I remove the <h1> tag, all works as expected... Anyone know a workaround?
Try this:
<div style="width: 300px; background-color: blue;">
<div style="height: 100px; background-color: green;"></div>
<div style="height: 100px; background-color: orange;">
<p>text</p>
</div>
</div>
Also, strangely enough, adding a border to the div holding the "text" solves the issue... But, that's not how it should work, should it?
<h1></h1>
<br>
<p></p>
Because your header is still a block element by default you don't need to add the br element, it will still break the line on it's own.
So what I'm saying is remove the margin and your problem should be solved.
John
the reason the margin:0px works is all the block leel elements are padded by default. It is kind of like the cellpadding in a <td> tag. If you add a border then say cellpadding="0" then the text will be right up against the border. If you make it 5 then it moves away, giving the <td> element some padding.
Same for the <h1> tags except the padding goes around the whole title element.
When I first went to CSS exclusive sites, I would put a border around everything when I ran into a problem. That helped me A Lot to see what was going on.
For your situation, it might have helped as you can see that the space beneath the h1 text is the same as the space above it. And since you know that it isn't padding, since the box is tight around the h1 text, it has to be margin...
<div style="width: 300px; background-color: blue;">
<div style="height: 100px; background-color: green;"></div>
<div style="height: 100px; background-color: orange;">
<h1 style="border:1px solid red;">Testing Margin</h1>
<span style="background-color:#ffffff;">test text beneath</span>
</div>
</div>
cheers,
gary