Default p setting in style sheet so that it shows the same in IE and FF

Discussion in 'CSS' started by fadetoblack22, Nov 21, 2008.

  1. #1
    I have a small problem with the paragraph text on my site.

    In IE all <p> text is pushed to the top of its container with no gap. The same at the bottom - there is no gap

    However in FireFox the <p> text has a nice gap at the top and bottom.

    I am assuming that they are just guessing because they don't know what to do.

    How do I set a value for this in the stylesheet so that it both does the same thing?

    thanks.
     
    fadetoblack22, Nov 21, 2008 IP
  2. katendarcy

    katendarcy Peon

    Messages:
    115
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Have you tried p{margin:0;padding:0;}? Of course, from there you'd need to add the styles you want. Also, at times I've found that it's necessary to be a little more specific when it comes to padding and margins of elements. For instance, say my outermost div had an id of "wrapper". Then, in the CSS I'll use #wrapper p{}, or maybe even go a div deeper if that doesn't work.
     
    katendarcy, Nov 21, 2008 IP
  3. drhowarddrfine

    drhowarddrfine Peon

    Messages:
    5,428
    Likes Received:
    95
    Best Answers:
    7
    Trophy Points:
    0
    #3
    Without a link, we can only guess.
     
    drhowarddrfine, Nov 21, 2008 IP
  4. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #4
    I did try that, but it seems to set the paragraphs with no line breaks between them for some reason. The text just ends up being a big block.
     
    fadetoblack22, Nov 21, 2008 IP
  5. katendarcy

    katendarcy Peon

    Messages:
    115
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hmmm... Even after adding something like "padding:0px 0px 10px 0px;" after that first declaration? Because, after setting things to zero, the initial effect would be that it's all one big block. That's a good thing! : ) The idea is that now you can build on that, changing the padding and margins as you need.
     
    katendarcy, Nov 21, 2008 IP
  6. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #6
    1. is normal in FF without putting p{margin:0}

    2. is with putting p{margin:0}

    In IE in both cases it looks like 2.

    [​IMG]
     
    fadetoblack22, Nov 21, 2008 IP
  7. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #7
    katendarcy have it right:
    start all p's out with margin and padding zero'd. This SHOULD remove the nice space you have in FF. If it only removes the space BETWEEN the p's but NOT at the top or bottom, then that space isn't coming from the p's in the first place, but from the padding of the container.

    If it's container padding, then you'll start out zeroing that. Check in all browsers that the zeroing really did remove the space in all browsers. Then, add in what you want.

    .reviewimg {
    padding: 10px 0;
    }

    that'll add 10px at the top and bottom, and none on the sides.

    Then with the p's, after they're zero'd:

    .reviewimg p {
    margin: 10px 0;
    }

    This should give you 10px worth of space between each p (margin collapse means each 10px won't be added together to make 20px). it might also add to the padding of the container too-- so play with it to see what you like.

    You don't actually have to zero everything before adding margins and padding-- it's needed if you have a lot of elements who you are not styling, because then the browsers will use their defaults, and the problem with the defaults is that what's default in FF is not default in IE (or Opera or Safari or whatever).
     
    Stomme poes, Nov 22, 2008 IP
  8. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Lawlz, I just saw someone posting pictures looking kinda similar, as far as, there's a lack of spacing in IE but there in FF.

    In that guy's case, the problem was resolved after adding a Doctype. So, if you don't have one of those, add one. : )
     
    Stomme poes, Nov 22, 2008 IP
  9. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #9
    Don't worry, there is definitely a doc type.
     
    fadetoblack22, Nov 22, 2008 IP
  10. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #10
    thanks, that helps. I wasn't aware that I had to zero things.

    is that margin to the top?

    I know that margin {0 0 0 0} is top, right, bottom, left.

    Is margin {10px 0} top, bottom?
     
    fadetoblack22, Nov 22, 2008 IP
  11. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #11
    This sounds like collapsed margins. IE wrongly collapses them where hasLayout gets involved.

    Without seeing at least a test case of some sort, all anyone can do is guess; as did I.

    cheers,

    gary
     
    kk5st, Nov 22, 2008 IP
  12. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Gary:
    does the 1px padding trick undo that in IE?

    Fade:
    Yeah. 10px on top, 10px on bottom, nothing on sides.

    Margin/padding/border: top right bottom left;
    Margin/padding/border: top sides bottom;
    Margin/padding/border: top-bottom sides;
    Margin/padding/border: all sides;
     
    Stomme poes, Nov 24, 2008 IP
  13. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #13
    Thanks, I tried that when you suggested it and it solved the problem. I just had to add a top and bottom margin to all my p elements after, which wasn't too hard.
     
    fadetoblack22, Nov 24, 2008 IP
  14. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #14
    No. See this test case. (standards mode)
    
    div {
    /*  float: left;  alternate version*/
        width: 300px;
        background-color: yellow;
        }
    
    .padded {
        padding: 1px;
        }
    =======================
    
    <div class="padded">
      <p>padded</p>
    </div>
    
    <div>
      <p>not padded</p>
    </div>
    Code (markup):
    As you see, in IE, the <p>'s margins collapses through its parent with or without padding. Modern browsers collapse only the unpadded version. In the floated <div>s, modern browsers do not collapse either, but IE collapses both.

    cheers,

    gary
     
    kk5st, Nov 24, 2008 IP