博主信息
博文 24
粉丝 0
评论 0
访问量 20634
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
盒模型,定位与浮动-2018年8月16日
鱼越龙门的博客
原创
960人浏览过

今天学习了盒子模型和定位的使用方法,要注意的是页面上看到的所有元素,都是盒子,文档流是元素的排列方式,总是水平排列,外边距在垂直方向上会发生塌陷,以数值大的为准,向大数值方向走
作业代码:

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>盒元素的基本要素</title>
	<style>
		.div1{
			width: 200px;
			height: 200px;
			background-color: red;
			padding-top:10px;
			padding-right:20px;
			padding-bottom: 30px;
			padding-left: 40px;
			border:1px solid blue;
			margin-bottom:20px;		
		}
		.div2{
			width: 200px;
			height: 200px;
			background-color: green;
			margin-top:50px;
		    border-left-width: 10px;
		    border-left-style: dashed;
		    border-left-color: black;
		}

	</style>
</head>
<body>
	<div class="div1">123</div>
	<div class="div2">321</div>
</body>
</html>

运行实例 »

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

代码2:

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>四种元素的对齐方案</title>
	<style>
		.div1{
			width: 400px;
			height: 400px;
			background-color: red;
			text-align: center;
			/*line-height: 400px;*/
		}
		.div1 span{
			line-height: 400px;
		}
		.div2{
			width: 400px;
			height: 400px;
			background-color: blue;
			text-align: center;
			display: table-cell;
			vertical-align: middle;
		}
		.div3{
			width: 400px;
			height: 400px;
			background-color: yellow;
			display: table-cell;
			vertical-align: middle;

		}
		.div3 .div3-1{
			width: 200px;
			height: 200px;
			background-color: grey;
			margin:0 auto;
		}
		.div4{
			width: 400px;
			height: 400px;
			background-color: pink;
			text-align: center;
			display: table-cell;
			vertical-align: middle;
		}
		.div4 ul{
			margin:0;
			padding:0;
		}
		.div4 li{
			display: inline;
		}
	</style>
</head>
<body>
	<!-- //单行行内元素对齐 -->
	<div class="div1">
		<span>123</span>
	</div>
	<br>
	<!-- //多行行内元素对齐 -->
	<div class="div2">
		<span>123</span><br>
		<span>321</span>
	</div>
	<br>
	<!-- //子元素是块元素对齐 -->
	<div class="div3">
		<div class="div3-1">123456</div>
	</div>
	<br>
	<!-- 子元素为不定宽的块元素 -->
	<div class="div4">
		<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>

运行实例 »

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

代码三:

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>十字架</title>
	<style>
	body{
		margin:0;
		padding: 0;
	}
		.box{
			width: 600px;
			position: relative;
		}
		.div1{
			width:200px;
			height: 200px;
			background-color: red;
			position: absolute;
			top:0;
			left:200px;
		}
		.div2{
			width:200px;
			height: 200px;
			background-color: yellow;
			position: absolute;
			top:200px;
			left:0;

		}
		.div3{
			width:200px;
			height: 200px;
			background-color: blue;
			position: absolute;
			top:200px;
			left:200px;
		}
		.div4{
			width:200px;
			height: 200px;
			background-color: green;
			position: absolute;
			top:200px;
			left:400px;
		}
		.div5{
			width:200px;
			height: 200px;
			background-color: grey;
			position: absolute;
			top:400px;
			left:200px;
		}

	</style>
</head>
<body><div class="box">
		<div class="div1"></div>
		<div class="div2"></div>
		<div class="div3"></div>
		<div class="div4"></div>
		<div class="div5"></div>
	</div>
</body>
</html>

运行实例 »

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

批改状态:合格

老师批语:缺少手写代码哦!
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系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+教程免费学