0

You can watch the problem here at jsfiddle - http://jsfiddle.net/Askerov/xz4t4bce/

The thing is i want to move the inside element, but i do not want parent element to move with it? Can anybody explain how it works? And how do i move such element?

.aa{
background:#ccc;
width:600px;
height:300px; } 
.bbb{
background:#333;
width:150px;
height:50px;
margin-top:40px;}

<div class='aa'>
<div class='bbb'>
</div>

Javid Askerov
  • 1,491
  • 1
  • 18
  • 32

2 Answers2

1

You're seeing collapsing margins. Just add overflow:auto; to the parent div to restore the behavior you seek

jsFiddle example

j08691
  • 197,815
  • 30
  • 248
  • 265
0

ALWAYS add the position of the elements, once you do that, it will allow you to move it, see here:

.aa{
    background:#ccc;
    width:600px;
    height:300px;
    position:relative;
}

.bbb{
    background:#333;
    width:150px;
    height:50px;
    top:40px;
    position:absolute;
}

jsFiddle

Alin
  • 1,128
  • 3
  • 19
  • 44