In the sample code, when I clicked the Show button, I got the location of the orange diva I needed (3) in relation to the diva (1) just below the diva's upper bound (1).
But if the content in divas 1, or 2 will stretch them down, then the arrangement I need diva_3 will eat. In the code example, div (3) comes after the first two. If you do it first:
<div id="v" style="display:none; margin-top:-255px; margin-left:12px;"> 3</div> <div style="width:350px; height:125px; background-color:silver;"> 1</div> <div style="width:350px; height:125px; background-color:grey;"> 2</div> <input type="button" value="Показать" style="width:173px;" onclick="f1()"> <input type="button" value="Скрыть" style="width:173px;" onclick="f2()"> then how to specify the styles, so as not to depend on the changing heights of divs 2 and 3? Well, the negative margin-top heard what to do wrong. Correct, please.
Code example:
function f1() { // Показать document.getElementById('v').style.display = 'block'; } function f2() { // Скрыть document.getElementById('v').style.display = 'none'; } #v { position:relative; z-index:5; width: 180px; height:180px; background: orange; } <div style="width:350px; height:125px; background-color:silver;"> 1</div> <div style="width:350px; height:125px; background-color:grey;"> 2</div> <input type="button" value="Показать" style="width:173px;" onclick="f1()"> <input type="button" value="Скрыть" style="width:173px;" onclick="f2()"> <div id="v" style="display:none; margin-top:-255px; margin-left:12px;"> 3</div> 