博客列表 >3_23 css元素对齐

3_23 css元素对齐

沈斌的博客
沈斌的博客原创
2018年03月24日 11:27:48683浏览

实例

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>css align</title>
	<style type="text/css">
		.box1 {
			width: 500px;
			height: 100px;
			text-align: center;
			background-color: lightblue;
		}

		.box1 h3 {
			line-height: 100px;
		}

		.box2 {
			width: 500px;
			
			height: 300px;
			font-size: 1.01em;
			display: table-cell;
			vertical-align: middle;
			background-color: lightcyan;
			background-image: url("./img/lightcolor.jpg");
			background-repeat: no-repeat;
			background-size: 100% 100%;
		}

		.box2 p {
			margin:auto;
			text-align: center;
		}

		.box3 {
			width: 500px;
			height: 100px;
			background-color: lightyellow;
			text-align: center;
			display: table-cell;
			vertical-align: middle;
		}

		.box3 a {
			text-decoration: none;
		}

		.box3 a:hover {
			text-decoration: underline;
			font-size: 1.04em;
			color: blue;
		}

		.box4 {
			width: 500px;
			height: 200px;
			background-color: lightgreen;
			text-align: center;
			display: table-cell;
			vertical-align: bottom;

		}

		.box4 li {
			list-style: none;
			display: inline;
		}


		.box4 ul {
			margin: 0;
			padding: 0;
			
		}




	</style>
</head>
<body>
	<!-- 单行文本对齐 -->
	<div class="box1">
		<h3 class="title">php</h3>
	</div>
	<hr>
	<!-- 块元素对齐 -->
	<div class="box2">
		<p id="para">
			
			坐倚狮峰涛渐起,<br>
			晚看流云景愈奇。<br>
			漫山松翠连天碧,<br>
			瞬息如海满谷底。<br>
		</p>
	</div>
	<hr>
	<!-- 多行文本对齐 -->
	<div class="box3">
		<a href="">2013.5</a><br>
		<a href="">2014.6</a><br>
		<a href="">2015.3</a><br>
	</div>
	<hr>

	<!--不定宽块元素对齐  -->
	<div class="box4">
		<ul class="item">
			<li><a href="">1</a></li>
			<li><a href="">2</a></li>
			<li><a href="">3</a></li>
			<li><a href="">4</a></li>
		</ul>
	</div>

</body>
</html>

运行实例 »

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


图片:

align.jpg

align2.jpg

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