tags:

views:

62

answers:

3

Please see my code, I don't understand why the margins of these divs are overlapping.

<div class="alignright">

    <div class="social">
        <a href="#" class="twit"></a>
        <a href="#" class="fb"></a>
    </div><!-- social -->

    <div class="contact">
        Get in Touch: <span>+44 10012 12345</span>            
    </div><!-- contact -->

    <div class="search">
        <form method="post" action="">
            <input type="text" value="" name="s" gtbfieldid="28">
        </form>
    </div><!-- search -->

</div>

The CSS:

.alignright {float: right}

#header .social {margin-top: 50px;}
#header .social a {display: inline-block;}
#header .social .fb {width: 64px; height: 1px; padding-top: 60px; overflow: hidden;}
#header .social .twit {width: 64px; height: 1px; padding-top: 60px; overflow: hidden;}

#header .contact {margin: 20px 70px 20px 0; font-size: 14px; font-weight: bold;}
#header .contact span {color: #FFFFFF;}

#header .search {margin: 10px 0 0;}

picture

+1  A: 

I think it's margin fusion. Only the largest margin between the bottom of the first element and the top of the second is taken into account.

It is quite normal to don't have too much space between two paragraphs eg.

You cannot avoid that with two adjacent elements so you have to enlarge or reduce the larger margin.

MatTheCat
why do it happen ? and how to remove that ?
atif089
Just lower your margin to what you want it to be.
Kissaki
Edited, just enlarge or reduce larger margin or use padding
MatTheCat
+1  A: 

Margins, in contrary to padding (which pads a specific width) is a “do this as a minimum distance”.

It won’t put that distance to all elements.

As you can see, the get in touch block bottom margin is marged to the input box. That is the margin active here. The other margin, top margin from the input, is not in effect, as it’s smaller and does not reach a block-element where it would actually push back the element. The 2 margins overlap and don’t effect one another.

Kissaki
+1  A: 

Why not just add 10px to your bottom margin in the .contact class?

Dave Kiss
did that, but wanted to know why it isnt working?
atif089
figured out that it isnt made to work that way :P Lol
atif089