Items below an item with a relative position and a negative top value remain where they are
I have 3 elements one on top of the other. If I give a second (pink) relative position and a negative top value, it will exceed the first. But the third does not "follow", staying where it is:
HTML:
<div id='div1'>text</div>
<div id='div2'>text</div>
<div id='div3'>text</div>
CSS
div {
padding: 50px;
}
#div1 {
background: yellow;
}
#div2 {
background: pink;
position: relative;
top: -50px;
}
#div3 {
background: gray;
}
How do I make the third and any other elements below it "follow" the pink element?
+3
source to share
8 answers
I'm not really sure what you want to achieve, but I hope everything is correct. put the following CSS in your third <div>
. Just check :)
position: relative;
top: -50px;
or,
margin-top: -50px;
another way,
div {
padding: 50px;
}
#div1 {
background: yellow;
width:100%;
}
#div2 {
background: pink;
position: relative;
top: -50px;
width:100%;
float:left;
}
#div3 {
background: gray;
width:100%;
}
+4
source to share
Check this link :
http://jsfiddle.net/silpa/dyg86qbq/16/
above link with relative position and margin-top. Here is a link with an absolute position for the first div and a margin-top for the second div. http://jsfiddle.net/silpa/dyg86qbq/22/
+1
source to share