CSS Position(定位)
position 属性指定了元素的定位类型,元素可以使用的顶部,底部,左侧和右侧属性定位。然而,这些属性无法工作,除非是先设定position属性。他们也有不同的工作方式,这取决于定位方法。
本文将介绍使用属性absolute 定位
代码`:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>演示居中</title>
<style type="text/css">
.box{
position: absolute;
top: 50%;
left:50%;
}
</style>
</head>
<body>
<form class="box" action="index.html" method="post">
<h1>哈喽</h1>
</form>
</body>
</html>
效果:
left表示标题下面放置距离左边的页面50%的px的元素。.
top表示标题下面放置距离顶部的页面50%的px的元素。.