Bae
Bae

Reputation: 912

Margin top move all my content

i have this html

<body id="page-id-login" class="">
<div id="viewport" data-am-control="vertical-layout" >
    <div id="container_buttons" data-am-control="vertical-layout" >
        <button class="item_vertical btn" >Twitter dinámico</button>
        <button class="item_vertical btn">Spinner simple</button>
        <button class="item_vertical btn">Spinner personalizado</button>
    </div>
</div><!-- END VIEWPORT-->

</body>

and this CSS

#viewport{
width: 480px;
height: 600px;
background: linear-gradient(#a8a8a8, #ebebeb);
}

#container_buttons{
padding: 0 10px;
}

.item_vertical{
display:inline-block;
}

.btn{
font-size: 20px;
color: white;
width: 100%;
padding-top: 5px;
padding-bottom: 5px;
background: linear-gradient(#0088cc, #0044cc);
border-style: solid;
border-width: 1px;
border-color:  #0044cc;
border-radius: 5px;
margin-top: 20px;
}

.btn:active{
background: linear-gradient(#0044cc, #0044cc);
border-style: solid;
border-width: 1px;
border-color:  #0044cc;
border-radius: 5px;
}

with this i see this:

http://img805.imageshack.us/img805/3980/capturadepantalla201305i.png

If i add to #container_buttons this:

#container_buttons{
margin: 60px;
padding: 0 10px;
}

the margin-top move all content (and not only the div #container_buttons) like you can see in this image (above there is blank space)

http://img20.imageshack.us/img20/6738/capturadepantalla201305iz.png

So... is there any way that margin only move div with id="container_buttons"?

Thanks!!

Upvotes: 0

Views: 1484

Answers (2)

technophobia
technophobia

Reputation: 2629

Your margins are collapsing, here's how to fix it:

#viewport {
    overflow:auto;
}

Source: CSS: Margin-top when parent's got no border

Reference: http://www.w3.org/TR/CSS2/box.html#collapsing-margins

Upvotes: 2

ooo
ooo

Reputation: 1627

You have to do something like this:

#viewport{
width: 480px;
height: 600px;
background: linear-gradient(#a8a8a8, #ebebeb);
}

#container_buttons{
    padding-top:10px;
    margin: 10px;
}

.item_vertical{
display:inline-block;
}

.btn{
    margin-bottom: 10px;
font-size: 20px;
color: white;
width: 100%;
background: linear-gradient(#0088cc, #0044cc);
border-style: solid;
border-width: 1px;
border-color:  #0044cc;
border-radius: 5px;
}

.btn:active{
background: linear-gradient(#0044cc, #0044cc);
border-style: solid;
border-width: 1px;
border-color:  #0044cc;
border-radius: 5px;
}

The result is now correct. I changed all padding and margin options because they were a little bit mixed up. Here is a fiddle of an example.

Upvotes: 0

Related Questions