JSFiddle - React, Tailwind, and code Playground
by Aaron Bickle
HTML
<div id="one">
<div id="two">
<div id="three">
<div id="four"></div>
</div>
</div>
</div>
<button id='randomize'>Randomize Position</button>
CSS
#one {
position: relative;
height: 200px;
width: 200px;
border: solid thin;
}
#two {
position: absolute;
top: 10px;
left: 10px;
height: 100px;
width: 100px;
border: solid thin;
}
#three {
position: relative;
top: 25px;
left: 25px;
height: 50px;
width: 50px;
border: solid thin;
}
#four {
position: absolute;
top: 5px;
left: 5px;
height: 25px;
width: 25px;
border: solid thin;
}
JavaScript
$("#randomize").click(function () {
var divTwo = $("#two");
var divThree = $("#three");
var randomTop, randomLeft;
// randomly position div two
divTwo.css('top', Math.floor(Math.random()*20) + 5);
divTwo.css('left', Math.floor(Math.random()*20) + 5);
divThree.css('top', Math.floor(Math.random()*50) + 20);
divThree.css('left', Math.floor(Math.random()*50) + 20);
});