1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Margin top and bottom issue in Chrome and Firefox

Discussion in 'CSS' started by guruguy, Oct 13, 2009.

  1. #1
    I have created a div within a div, however the problem is that any attempt to add margins to the top or bottom for the internal div results in moving the container div. The code is as below:

    HTML:
    
    <div class="border">
        <div class="main">
            <p>
                hi
            </p>
        </div>
    </div>
    
    Code (markup):
    CSS:
    
    div.border {
        width: 750px;
        background-color: #FFF000;
        margin-left: auto;
        margin-right: auto;
        background: url('images/gradient.png');
    }
    
    div.main {
        border: 5px;
        border-color: #000000;
        border-style: solid;
        width: 700px;
        height: auto;
        margin-left: auto;
        margin-right: auto;
        margin-top: 10px;
        margin-bottom: 10px;
        background: #FFFFFF;
    }
    
    Code (markup):
    This is how it displays in firefox and chrome:
    [​IMG]

    This is how it shows in IE, the way I want it to show in other browsers:
    [​IMG]

    Any help would be great. I'm not that crash hot at CSS so it may be something extremely obvious.
    Thanks
     
    guruguy, Oct 13, 2009 IP
  2. wanovak

    wanovak Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Set a definite height for your border div.
     
    wanovak, Oct 16, 2009 IP
  3. Masterful

    Masterful Well-Known Member

    Messages:
    1,653
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    140
    #3
    Try getting rid of the top and bottom margin of the main div, and adding top and bottom padding to the border div, thus:

    div.border {
        width: 750px;
        background: #fff000 url(images/gradient.png);
        margin: 0 auto;
        padding: 10px 0;
    }
    
    div.main {
        border: solid 5px #000;
        width: 700px;
        margin: 0 auto;
        background-color: #fff;
    }
    Code (markup):
     
    Masterful, Oct 19, 2009 IP
  4. drhowarddrfine

    drhowarddrfine Peon

    Messages:
    5,428
    Likes Received:
    95
    Best Answers:
    7
    Trophy Points:
    0
    #4
    I don't have IE available to look at it but the thing to always remember is Firefox will show what you wrote while IE will make things up as you go along. Trust what Firefox is showing you. Get it working there first. Then hack IE for its many quirks and bugs.
     
    drhowarddrfine, Oct 20, 2009 IP