- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
- <title> * emu * </title>
- <SCRIPT>
- <!--
- window.onresize = resetDIV;
- function resetDIV()
- {
- with(document.getElementsByTagName("DIV")[0].style)
- {
- left = (document.body.offsetWidth-parseInt(width))/2
- top = (document.body.offsetHeight-parseInt(height))/2
- }
- }
- //-->
- </SCRIPT>
- </head>
- <body onload="resetDIV()">
- <div style="position:absolute;width=200;height=200;background-color=yellow"></div>
- </body>
- </html>
本文介绍了一种使用JavaScript实现网页元素自动居中的方法。通过监听窗口大小变化并调整元素的位置,使得一个指定大小的黄色方块始终处于浏览器窗口的正中央。这种方法适用于创建弹窗或特殊视觉效果。
844

被折叠的 条评论
为什么被折叠?



