我從w3schools.com看到這個例子。該網站說,什麼位置屬性應該分配給「容器」元素和「動畫」元素? html css javascript
容器元素應該創建與style =「位置:相對」。 應該使用style =「position:absolute」創建動畫元素。
我不明白爲什麼會出現這種情況。有人請向我解釋一下。
<!Doctype html>
<html>
<style>
#container {
width: 400px;
height: 400px;
position: relative;
background: yellow;
}
#animate {
width: 50px;
height: 50px;
position: absolute;
background: red;
}
</style>
<body>
<h1>My First JavaScript Animation</h1>
<div id="container">
<div id="animate"></div>
</div>
</body>
</html>