Blogger Information
Blog 16
fans 1
comment 0
visits 10016
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0323
烟火的博客
Original
842 people have browsed it
实例
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>0323作业</title>
	<style type="text/css">
		.box1 {
			width: 200px;
			height: 200px;
			background-color: lightblue;
			text-align: center;
		}
		.box1 a {
			line-height: 200px;
		}

		.box2 {
			width: 200px;
			height: 200px;
			background: red;
			text-align: center;
			display: table-cell;
			vertical-align: middle;
		}

		.box3 {
			width: 200px;
			height: 200px;
			background: yellow;
			display: table-cell;
			vertical-align: middle;
		}
		.box3 .box4{
			width: 100px;
			height: 100px;
			background-color: blue;
			margin:auto;
		}

		.box5 {
			width: 200px;
			height: 200px;
			background-color: lightblue;
			text-align: center;
			display: table-cell;
			vertical-align: bottom;
		}
		.box5 ul {
			padding: 0px;
		}
		.box5 li {
			list-style: none;
			display: inline;
		}
	</style>
</head>
<body>
	<!-- 单行文本居中
	1.水平居中:在父元素样式里面设置text-align:center;
	2.垂直居中:在子元素样式里面设置line-height等于父元素的高; -->
	<div class="box1"><a href="">单行文本居中</a></div>
	
	<!-- 多行文本居中-->
		<!--1.水平居中:在父元素样式里面设置text-align:center;
			2.垂直居中:在父元素里面设置display:table-cell;verticle-align:middle; -->
	<div class="box2">
		<a href="">多行文本居中</a><br>
		<span>多行文本居中</span>
	</div>
	<!-- 块元素居中
	1.水平居中:子元素设置为margin:auto;
	2.垂直居中:父元素display:table-cell;verticle-align:middle; -->
	
	<div class="box3">
		<div class="box4"></div>
	</div>

	<!-- 不定宽块元素居中
	1.水平居中:设置text-align:center;
	2.垂直居中:设置ul的属性为line-height等于父元素height(不常用)
	3.底部居中:设置为display:table-cell;verticle-align:bottom -->
	<div class="box5">
		<ul>
			<li><a href="">1</a></li>
			<li><a href="">2</a></li>
			<li><a href="">3</a></li>
			<li><a href="">4</a></li>
			<li><a href="">5</a></li>
		</ul>
	</div>

</body>
</html>
运行实例 »
点击 "运行实例" 按钮查看在线实例


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