Blogger Information
Blog 55
fans 0
comment 1
visits 42242
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
常见的四种元素对齐方式-2018年3月23日零点
旺小舞的博客
Original
691 people have browsed it

效果图:

四种对齐方式.jpg

知识点:

    1,单个行内元素    水平居中:text-align:center;    垂直:line-hight:"父元素高度"

    2,多个行内元素    水平居中:text-align:center;    垂直:display:table-cell;    vertical-align:middle;

    3,块元素              水平居中:margin:aoto;    垂直:dispaly:table-cell;    vertical-align:middle;

    4,不定宽元素(无效列表)    水平居中:text-align:center    垂直:display:table-cell;    vertical-align:middle/bottom


代码:

实例

<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>
	<title>子元素的四种对齐方式</title>
	<style type="text/css" media="screen">
		#box1{
			width: 200px;
			height: 150px;
			background-color: lightblue;
			text-align: center;
		}
		#box1 span{
			line-height: 150px;
		}
		#box2{
			width: 200px;
			height: 150px;
			background-color: lightcyan;
			text-align: center;
			/*类型转换为表格单元格*/
			display: table-cell;
			/*垂直居中*/
			vertical-align: middle;
		}
		#box3{
			width: 200px;
			height: 150px;
			background-color: lightskyblue;
			display: table-cell;
			vertical-align: middle;

		}
		.box31{
			width: 150px;
			height: 100px;
			background-color: brown;
			margin: auto;

		}
		#box4{
			width: 200px;
			height: 150px;
			background-color: lightcoral;
			text-align: center;
			display: table-cell;
			vertical-align: bottom;	
		}
		#box4 li{
			list-style-type:none;
			display: inline;

		}
		#box4 ul{
			padding-left:0; 
		}

		
	</style>
</head>
<body>
	<div id="box1">
		<span>我是单个行内元素</span>
	</div>
	<div id="box2">
		<a href="" title="">我是第一个行内元素</a>
		<p>我是第二个行内元素</p>
	</div>
	<div>
		
	</div>
	<div id="box3">
		<div class="box31">
			
		</div>
	</div>
	<div>
		
	</div>
	<div id="box4">
		<ul>
			<li>1</li>
			<li>2</li>
			<li>3</li>
			<li>4</li>
			<li>5</li>
		</ul>
	</div>


</body>
</html>

运行实例 »

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

手稿:

3-23.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