html 水平垂直居中

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
			<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no"/>
		<title></title>
		<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}
			#box{
				width:400px;
				height:600px;
				background-color: aquamarine;
				margin:auto;
				position: relative;
			}
			#inter{
				width: 100px;
				height:100px;
				background-color: red;
				position: absolute;
				left:0;
				top:0;
				right: 0;
				bottom: 0;
				margin: auto;
				
				
			}
		</style>
	</head>
	<body>
	
		<div id="box">
			<div id="inter">
				hhh<br>
			</div>
		</div>
		
	</body>
</html>
<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}
			#box{
				width:400px;
				height:600px;
				background-color: aquamarine;
				margin:auto;
				position: relative;
			}
			#inter{
				width: 100px;
				height:100px;
				background-color: red;
				position: absolute;
				left:50%;
				top:50%;
				margin-left:-50px;
				margin-top:-50px;
				
			}
		</style>
<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}
			#box{
				width:400px;
				height:600px;
				background-color: aquamarine;
				margin:auto;
				position: relative;
			}
			#inter{
				width: 100px;
				height:100px;
				background-color: red;
				position: absolute;
				left: 50%;
				top:50%;				
				transform: translate3d(-50%,-50%,0);
				
			}
		</style>

 

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