博主信息
博文 27
粉丝 0
评论 0
访问量 22282
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
盒子模型,定位与元素位置-8.16
Yyk.的博客
原创
858人浏览过

盒子模型:

实例

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>盒子模型</title>
	<style>
		.zero{background: #7F5DD0;
		width: 500px;
		height: 500px;
		margin: 0;
		padding: 50px;
		}
		
		.one{background: #B34B4D;
		width: 200px;height: 200px;
		border: 3px solid black;
		margin: 10px;
		padding: 10px;
		}
		
		.two{background: #57CD7B;
		width: 200px;height: 200px}
	</style>
</head>

<body>
	<div class="zero">
		<div class="one">11</div>
		<div class="two">11</div>
	</div>
	
</body>
</html>

运行实例 »

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

十字架

实例

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>十字架</title>
	<style type="text/css">
		.big{background: #ccc;
		height: 600px;
		width: 600px;
		position: relative;
		margin: auto;
		padding: auto}
		
		.one{background: #4ABD45;
		width: 200px;
		height: 200px;
		position: absolute;
			left: 200px;
		margin: auto
		
		}
		.two{background: #CF383B;
		width: 200px;
		height: 200px;
		position: absolute;
		top: 200px}
		.three{background: #4487C5;
		width: 200px;
		height: 200px;
		position: absolute;
		top: 200px;left: 400px}
		.four{background: #E35AAB;
		width: 200px;
		height: 200px;
		position: absolute;
		top: 200px;left: 200px}
		.five{background: #150C32;
		width: 200px;
		height: 200px;
		position: absolute;
		top: 400px; left: 200px}
	
	</style>
</head>

<body>
	<div class="big">
	<div class="one"></div>
	<div class="two"></div>
	<div class="three"></div>
	<div class="four"></div>
	<div class="five"></div>
	</div>
</body>
</html>

运行实例 »

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

四种元素对齐方式

实例

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>四种元素对齐方式</title>
</head>

<body>
	
	<b>1.
	子元素是单行行内元素(a,span)</b><br>
	a.
	水平居中:在父元素应用:text-align:center<br>
	b.
	垂直居中:设置行内元素行高line-height=height
	<div style="height: 100px;
				width: 100px;
				background: red;
				text-align: center">
	<a style="line-height: 100px">行元素</a>
	</div>
	
	<br>
	<br>
	
	
	
	<b>2.子元素的多行行内文本</b><br>
	a.水平居中:在父元素应用:text-align:center<br>
	b.垂直居中:在父元素应用display:table-cell和vertical-align: middle
		<div style="height: 100px;
					width: 100px;
					background: red;
					text-align: center;
					display: table-cell;
					vertical-align: middle"
		>
	<a>这是一个多行元素</a>
	</div>
	<br><br>
	
	
	
	<b>3.子元素是块元素</b><br>
	a.水平居中:子元素设置margin:auto<br>
	b.垂直居中:在父元素应用display:table-cell和vertical-align: middle
	<div style="width: 200px;height: 200px;background: #7F7ED5;display: table-cell;
				vertical-align: middle">
	<div style="height: 100px;width: 100px;background: #DC3E27;margin: auto"></div>
	</div><br><br>
	
	
	<b>4.子元素是不定宽的块元素(变化的)</b><br>
	a.水平居中:子元素转化为行元素,父级加text-align:center
	<br>
	b.垂直居中:父元素应用dispaly:table-cell;vertical-align-center
	<br>
	<div style="width: 200px;height: 200px;background: #B87C7D;
				text-align: center;display: table-cell;vertical-align: middle">
	<ul style="margin: 0;padding-left: 0">
		<li style="display: inline">1</li>
		<li style="display: inline">2</li>
		<li style="display: inline">3</li>
		<li style="display: inline">4</li>
		<li style="display: inline">5</li>
		<li style="display: inline">6</li>
		
	</ul>
	</div>
	

</body>
</html>

运行实例 »

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

个人总结:

    盒子模型是很重要的一个知识点,从内到外依次是content,border,padding,margin.

    绝对定位是相对于父元素;相对定位是相对于元素应处的位置

    四种元素对齐方式:1.行内单行元素。2.行内多行元素。3.块级元素。4.块级不定宽元素


批改状态:未批改

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学