HTML中body代码:
<body>
<div class="divForm">
<form action="" method="post">
<p>
欢迎登陆网站主页
</p>
<p>
用户名:<input type="text" name="username"/>
</p>
<p>
密 码:<input type="password" name="password"/>
</p>
<input type="submit" value="提交"/>
</form>
</div>
</body>
然后,head中的style代码:
<style type="text/css">
.divForm{
position: absolute;/*绝对定位*/
width: 300px;
height: 200px;
border: 1px solid red;
text-align: center;/*(让div中的内容居中)*/
top: 50%;
left: 50%;
margin-top: -200px;
margin-left: -150px;
}
</style>
form本来就只是一个表单而已,对页面根本就没有布局上的作用..需要的话利用div来套。各位朋友可亲测,完了后,将border: 1px solid red;去掉即可