homepage Welcome to WebmasterWorld Guest from 54.227.77.237
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / CSS
Forum Library, Charter, Moderator: open

CSS Forum

    
Extra padding on DIV tag in Firefox
lateatnight




msg:3083756
 2:26 am on Sep 15, 2006 (gmt 0)

I have a DIV tag that is giving me grief. Even though I have no top padding on the DIV tag, Firefox is displaying it with what looks like 20px at the top. Works fine in IE. Have double checked that nothing else in my CSS would add any padding.

<div id="text" style="position:absolute; width:380px; height:92px; z-index:1; background-color: #FFFFFF; background-color: #FFFFFF; overflow: auto; padding-left: 5px;">

 

icantthinkofone




msg:3083776
 2:45 am on Sep 15, 2006 (gmt 0)

The default margin among browsers is different. It's best just to set all margins and padding to zero. *{margin:0;padding:0} and then put them into each element as needed.

penders




msg:3084060
 10:04 am on Sep 15, 2006 (gmt 0)

What's inside the DIV?

lateatnight




msg:3085109
 3:58 am on Sep 16, 2006 (gmt 0)

Thanks, the *{margin:0;padding:0} did the trick. However, instead of my DIV being 380px wide in Firefox, it looks more like 390px. How to pad just what's inside the DIV without affecting anything else?

icantthinkofone




msg:3085368
 1:03 pm on Sep 16, 2006 (gmt 0)

You pad inside the box by using 'padding'.

Are you saying the padding inside the box is different than in IE? If so, then it's possible you are using IEs broken box model. What doctype are you using?

The Box Model [w3.org]

penders




msg:3086416
 1:57 pm on Sep 17, 2006 (gmt 0)

How to pad just what's inside the DIV without affecting anything else?

<p>Don't style this paragraph... leave as default</p>
<div id="mydiv">
<p>Pad and style this paragraph</p>
<p>... and this one too.</p>
</div>

div#mydiv p {
padding:1em;
font-size:larger;
color:#f00;
}

This will pad (and style) just the <p> tags that are within the div id="mydiv"

SuzyUK




msg:3086459
 3:21 pm on Sep 17, 2006 (gmt 0)

I think it sounds like a collapsing margin, hence the removal of them made it look the same.

To contain collapsing margins consistently x-browser in non-positioned elements, usually all that's needed is to add 1px top/bottom padding to the div (or a top/bottom border) - this stops the div margin adjoining with the elements inside it, and stops any collapsing

In all cases, especially floated and positioned elements thi above might not be enough for IE because it sometimes collapses them entirely, to goodness knows where!
(this is what's happening using the example above I think, not sure as I don't know what was inside it)

Rule of thumb for IE, don't rely on the default margins of the <p>, <hx>, <ul>, <form> elements (any really) inside the div, explicitly give them margins.. e.g. p {margin: 1em 0;}

try this for example of difference, then uncomment the p margin to see IE come into line with FF, if you then don't want a top gap you can just remove the margin from the top paragraph.

longwinded perhaps, but a least you know what's generating the "gap" and IE should be generating one too ;)

<style type="text/css" media="screen">
#text {
position:absolute;
top: 0;
left: 0;
width:380px;
height:92px;
background-color: #eee;
padding-left: 5px;
}

/*p {margin: 1em 0;}*/
/*p.topp {margin-top: 0;}*/
</style>
</head>
<body>
<div id="text">
<p class="topp">some text here</p>
<p>some text here</p>
</div>

[edited by: SuzyUK at 7:59 am (utc) on Sep. 19, 2006]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / CSS
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved