1

Have such code:

<div style="position:relative">
    <div id="t1" style="position:relative; top:100; left:100;"></div>
    <div id="t2" style="position:relative; top:200; left:200;"></div>
</div>

<script>
$(function () {
    $('#t1').remove();
);
</script>

after that script div-t2 is moving randomly to another place, and if i remove t2, then t1 moves. how to make their position stable, i dont want them to travel on my screen.

4 Answers 4

2

change position: relative to position: absolute (relative to the parent) or position: fixed (relative to the document)

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

1 Comment

Mister G, you entered the solution exact the same moment i did - respect :)
1

Use absolute positioning

<div style="position:relative">
    <div id="t1" style="position:absolute; top:100px; left:100px;"></div>
    <div id="t2" style="position:absolute; top:200px; left:200px;"></div>
</div>

and also add a unit to your position values (i have added px)

Comments

1

The positions of t1 and t2 are relative to where they would be in the normal run of HTML rendering.

To achieve what you want, make the position of t1 and t2 absolute.

Comments

0

Give them (the inner divs) style="position:absolute".

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.