应用场景: 在body中书写一个代码块, 使其相对于body垂直居中
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>居中测试</title>
<style type="text/css">
body{
position: relative;
margin: 0;
padding: 0;
width: 100vw;
height: 100vh;
}
#clock{
width: 300px;
height: 100px;
margin: auto;
position: absolute;
top: 0; bottom: 0;
left: 0; right: 0;
background: chocolate;
}
</style>
</head>
<body>
<!-- 需求: 利用setInterval定时器写一个走动的时钟 -->
<div id="clock">
111
</div>
<script>
window.onload = function(){
}
</script>
</body>
</html>