DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> CSS入門知識 >> CSS特效代碼 >> 不定高度實現居中顯示
不定高度實現居中顯示
編輯:CSS特效代碼     
<!DOCTYPE html>
<html>
<meta name="name" content="content" charset='utf-8'>
<head>
	<title>網頁居中</title>
</head>
<style type="text/css" media="screen">
	*{margin:0;padding: 0;}
	.al{width: 800px;height: 600px;margin: 30px auto;position: relative;border:1px solid red;}
	.par{position: absolute;top:50%;left:50%;}
	.chd{background: green;position: relative;top:-50%;left:-50%;}
	.ul{width: 600px;height:400px;margin: 10px auto;border:1px solid blue; }
	.ul li{width: 50px;height: 30px;border:1px solid red;text-align: center;line-height: 30px;list-style-type: none;float:left;margin: 20px 0 0 20px;}
</style>
<body>
<div class="al">
	<div class="par">
		<div class="chd">
			我要居中我要居中
		</div>
	</div>
</div>
</body>
</html>

  第二種方法

<!DOCTYPE html>
<html>
<meta name="name" content="content" charset='utf-8'>
<head>
	<title>網頁居中</title>
</head>
<style type="text/css" media="screen">
	*{margin:0;padding: 0;}
	.al{width: 800px;height: 600px;margin: 30px auto;}
	.par{width: 800px;height: 600px;border:1px solid red;display: table-cell;text-align: center;vertical-align: middle;}
	.chd{background: green;display: inline-block;}

</style>
<body>
<div class="al">
	<div class="par">
		<div class="chd">
			我要居中我要居中
		</div>
	</div>
</div>
</body>
</html>
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved