1

I have 3 boxes. When setting the middle's position to relative (to 'body' in this case) and negative top, the box below doesn't move up too. How could I do that?

HTML:

<div class="box" id="up"></div>
<div class="box" id="middle"></div>
<div class="box" id="down"></div>

CSS:

.box {
  width: 400px;
  height:200px;
  position: relative;
}

#up {
  background: red;
}

#middle {
  top: -50px;
  background: green;
}

#down {
  background: blue;
}

http://codepen.io/anon/pen/dBgbz/

EDIT: I forgot to say that I've tried with negative margin-top, but works except for Internet Explorer. Is there any other way to do it?

2
  • Basically, you want the blue box to follow the green box's position? Commented Mar 24, 2014 at 5:04
  • Yes. I've tried with margin-top I forgot to say, and works except for Internet Explorer. Commented Mar 24, 2014 at 5:41

2 Answers 2

2

Define your #middle margin-top: -50px and remove top : -50px

#middle {
margin-top:-50px;  // add this  
top: -50px;  // remove this 
  background: green;
}

Demo

Sign up to request clarification or add additional context in comments.

1 Comment

I forgot to say that I've tried that, but the problem is that way it doesn't work on IE...
0

Do you add the top yet to #down box:

#down {
  top: -50px;
  background: blue;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.