Blogger Information
Blog 31
fans 0
comment 1
visits 24656
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
20180323的作业
jobing的博客
Original
452 people have browsed it

代码:

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>元素的对齐</title>
	<style type="text/css">
	/*1.子元素是行内元素*/
		.square1{
			width: 300px;
			height: 300px;
			background: pink;
			/*设置父元素的text-align,可水平居中*/
			text-align: center;
		}
		.square1 span{
            /*设置子元素与父元素高度一致,可垂直居中*/
			line-height: 300px;
		}
		/*2.子元素是多行内联文本*/
		.square2{
			width: 300px;
			height: 300px;
			background: pink;
			/*设置父元素的text-align,可水平居中*/
			text-align: center;
			/*设置父元素的display和vertecal-align,可垂直居中*/
			display: table-cell;/*设置显示方式为表格单元*/
			vertical-align: middle;/*设置单元格内的元素垂直居中*/
		}
		/*3.子元素是块元素*/
		.square3{
			width: 300px;
			height: 300px;
			background: pink;
            /*设置父元素的display和vertecal-align,可垂直居中*/
			display: table-cell;/*设置显示方式为表格单元*/
			vertical-align: middle;/*设置单元格内的元素垂直居中*/
		}
		.square3 .square3-1{
			width: 100px;
			height: 100px;
			background-color: yellow;
            /*设置子元素的margin,可水平居中*/
			margin: auto;
            /*设置子元素的text-align,可使子元素的行内元素水平居中*/
			text-align: center;
		}
		.square3 .square3-1 span{
            /*设置子元素的子元素line-height,可使子元素的行内元素垂直居中*/
			line-height: 100px;
		}
		/*4.子元素是不定宽的块元素,如分页导航*/
		.square4{
			width: 300px;
			height: 300px;
			background: pink;
            /*可使子元素水平居中*/
			text-align: center;
			/*可使子元素垂直居中*/
			display: table-cell;/*设置显示方式为表格单元*/
			vertical-align: bottom;/*设置单元格内的元素垂直居中*/
		}
		.square4 ul{
			margin: 0;
			padding: 0;
		}
		.square4 ul li{
			list-style:none;
			display: inline; 
		}
	</style>
</head>
<body>
	<div class="square1">
		<span>我是jobing</span>
	</div>
	<hr>
	<div class="square2">
		<span>我是jobing</span><br>
		<span><a href="http://www.php.cn/blog/jobing.html">我的博客</a></span>		
	</div>
	<hr>
	<div class="square3">
		<div class="square3-1"><span>我是jobing</span></div>
	</div>
	<hr>
	<div class="square4">
		<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>
			<li><a href="">...</a></li>
			<li><a href="">尾页</a></li>
		</ul>
	</div>
	

</body>
</html>

运行实例 »

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

手写代码:

1.jpg2.jpg3.jpg4.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