<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
#box{
width: 400px;
height: 400px;
border: #FFC0CB solid 2px;
position: relative;
overflow: hidden;
}
.two{
position: relative;
}
.one{
position: absolute;
}
</style>
</head>
<body>
<div id="box">
<div id="food"></div>
</div>
<script>
var box = document.getElementById("box");
var food = document.getElementById("food");
box.className="two";
food.style.width="20px";
food.style.height="20px";
food.style.background="red";
food.style.left = Math.floor(20*Math.random()*20)+"px";
food.style.top = Math.floor(20*Math.random()*20)+"px";
food.className="one";
</script>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
#box{
width: 400px;
height: 400px;
border: #FFC0CB solid 2px;
position: relative;
overflow: hidden;
}
.two{
position: relative;
}
.one{
position: absolute;
}
</style>
</head>
<body>
<div id="box">
<div id="food"></div>
</div>
<script>
var box = document.getElementById("box");
var food = document.getElementById("food");
box.className="two";
food.style.width="20px";
food.style.height="20px";
food.style.background="red";
food.style.left = Math.floor(20*Math.random()*20)+"px";
food.style.top = Math.floor(20*Math.random()*20)+"px";
food.className="one";
</script>
</body>
</html>