css垂直居中

固定寬高的div在瀏覽器居中(cvte在線測評) 和單行文字居中,

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>center</title>
</head>
<style>
#center{
	position:absolute;
	width:400px;
	height:300px;
	background:#ff0;
	top:calc(50% - 150px);
	left:calc(50% - 200px);
	text-align:center;
	line-height:300px;
}
</style>
<body>
<div id="center">單行文字居中</div>
</body>
</html>

第二種

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>第二種垂直居中</title>
</head>
<style>
#wrapper{
	position:absolute;
	top:0;
	bottom:0;
	left:0;
	right:0;
	margin:auto;
	height:240px;
	width:70%;
	background:blue;
}
</style>
<body>
<div id="wrapper">456
</div>
</body>
</html>




 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章