Blogger Information
Blog 10
fans 0
comment 1
visits 6264
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
3月23
不忘初心
Original
605 people have browsed it

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>CSS四种对齐方式</title>
	<style type="text/css">
		/*单行文本居中*/
		.box1{
			width: 200px;
			height: 200px;
			background-color: lightblue;/*水平居中*/
			text-align: center;
		}
		
		/*多行文本居中*/
		.box2{
			width: 200px;
			height: 200px;
			background-color: #FF7300;
			text-align: center;/*水平居中*/
			display: table-cell;/*把盒子变成表格*/
			vertical-align: middle;/*垂直居中*/
		}
        .box2 span{
			width: 100px;
			height: 100px;
			line-height: 200px;/*垂直居中*/
		}

		/*块级元素居中*/
		.box3{
			width: 200px;
			height: 200px;
			background-color: green;
			text-align: center;/*水平居中*/
			display: table-cell;/*把盒子变成表格*/
			vertical-align: middle;/*垂直居中*/
		}
		.box3 p{
			width:100px;
			margin: auto;
		}
	</style>
</head>
<body>
	
	<div class="box1">
		<a href="">PHP中文网</a>
	</div>
	<div class="box2">
		<span>PHP世界上最好的语言</span><br>
		<span>PHP-China</span>
	</div>
	<div class="box3">
		<p>hello world</p>
	</div>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

微信图片_20180325215350.jpg微信图片_20180325215402.jpg

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post