博客列表 >3月23

3月23

不忘初心
不忘初心原创
2018年03月25日 21:54:33585浏览

实例

<!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

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议