/    Sign up×
Community /Pin to ProfileBookmark

IE & Floated DIVS margin problem

Hello all, I have been reading alot about IE’s rendering problems with margins etc and “haslayout”.

My problem is I have a floated div and inside that div, the first <p> tag does not have any top margin in ie7, but it does in firefox. I have read about using overflow etc to force margins but I can not get it to work. To simplify things, i will show you what code i want to work. Any suggestions would be greatly appreciated!

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>
<html xmlns=”http://www.w3.org/1999/xhtml“>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
</head>

<body>
<div style=”float:left; width:75%; border:solid 1px #000000; “>
<p style=”font-size:1em;border:solid 1px #000000; width:100%;”>TEST</p>
<h1 style=”font-size:1em;border:solid 1px #000000;”>TEST</h1>
</div>
</body>
</html>

So what i need is there to be the same margin? (space) from the top of the page to the first p tag in ie and firefox. IE has none, firefox does.

to post a comment
CSS

3 Comments(s)

Copy linkTweet thisAlerts:
@CentauriJun 02.2008 — Different browsers use different default margins for elements, including <p>. If you want the same margins in each browsers, specify them rather than rely on defaults [CODE]p {
margin: 1em 0;
}[/CODE]
Copy linkTweet thisAlerts:
@ripper2020authorJun 02.2008 — Different browsers use different default margins for elements, including <p>. If you want the same margins in each browsers, specify them rather than rely on defaults [CODE]p {
margin: 1em 0;
}[/CODE]
[/QUOTE]

Thanks, and although thats true, the problem is only with the first child element of the floated div. So the next <p> tag would have proper spacing above and below it. Why is it only the first one?
Copy linkTweet thisAlerts:
@CentauriJun 02.2008 — I am guessing that IE does not apply a top margin to <p>s by default, only a bottom one - don't have the time right now to check that out though.
×

Success!

Help @ripper2020 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...