1: 应用场景 在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="X-UA-Compatible" content="ie=edge"> <title>js定时器setTimeout_setInterval的用法</title> <style type="text/css"> body{ position: relative; margin: 0; padding: 0; 100vw; height: 100vh; } #clock{ 300px; height: 100px; margin: auto; position: absolute; top: 0; bottom: 0; left: 0; right: 0; background: cyan; } </style> </head> <body> <!-- 需求: 利用setInterval定时器写一个走动的时钟 --> <div id="clock"> 111 </div> <script> window.onload = function(){ } </script> </body> </html>
2: 这样就OK啦 !