【慕课网】前端零基础入门---步骤二:页面化妆师CSS---03-盒子模型

03-盒子模型

第1章 盒子模型的概念

在这里插入图片描述

第2章 盒子模型属性

2-1 width属性

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

<!DOCTYPE html>
<html>
<head>
	<title>3</title>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
	<style type="text/css">
		div{width: 600px;background: pink;}
		.one{width: 50%;background: yellow;}
		.two{max-width: 30%;background: yellow;}
		.three{min-width: 70%;background: yellow;}
	</style>
</head>
<body>
	<div>
		<p class="one">第一个p标签是父元素宽度的50%</p>
		<p class="two">第二个p标签的最大宽度是父元素的30%</p>
		<p class="three">第三个p标签的最小宽度是父元素的70%</p>
	</div>
</body>
</html>

2-2 height属性

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

<!DOCTYPE html>
<html>
<head>
	<title>3</title>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
	<style type="text/css">
		div{width: 600px;background: pink;height: 600px;}
		.one{width: 30%;background: yellow;height: 30%;}
		.two{max-width: 30%;background: yellow;max-height: 30%;}
		.three{max-width: 300px;background: yellow;min-height: 200px;}
	</style>
</head>
<body>
	<div>
		<p class="one">第一个p标签是父元素宽、高的30%</p>
		<p class="two">第二个p标签的最大宽度是父元素的30%,最大高度是父元素的30%</p>
		<p class="three">第三个p标签的最小高度是200px,最大宽度是300px</p>
	</div>
</body>
</html>

2-3 哪些元素可设置width和height属性

在这里插入图片描述
在这里插入图片描述

2-4 border边框属性

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

<!DOCTYPE html>
<html>
<head>
	<title>3</title>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
	<style type="text/css">
		li{width: 200px;height: 50px;}
		.li1{border-top: 2px red solid;}
		.li2{border-right: 2px green dotted;}
		.li3{border-bottom: 2px blue dashed;}
		.li4{border-left: 3px purple double;}
		.li5{border: 2px orange solid;}
	</style>
</head>
<body>
	<ul>
		<li class="li1">第一个li</li>
		<li class="li2">第二个li</li>
		<li class="li3">第三个li</li>
		<li class="li4">第四个li</li>
		<li class="li5">第五个li</li>
	</ul>
</body>
</html>

2-5 padding填充属性

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

<!DOCTYPE html>
<html>
<head>
	<title>3</title>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
	<style type="text/css">
		.container{
			width: 200px;
			height: 200px;
			background-color: pink;
			padding-top: 50px;
			padding-left: 100px;
		}
		.content{
			width: 100px;
			height: 100px;
			background-color: orange;
			padding-top: 30px;
			padding-left: 30px;
			padding-right: 30px;
		}
		span{background-color: yellow;}
	</style>
</head>
<body>
	<div class="container">
		<div class="content">
			<span>我是span元素</span>
		</div>
	</div>
</body>
</html>

2-6 margin外边距属性

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

<!DOCTYPE html>
<html>
<head>
	<title>3</title>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
	<style type="text/css">
		*{
			margin: 0;
			padding: 0;
		}
		ul{
			list-style: none;
			width: 300px;
			height: 400px;
			background-color: pink;
			padding-top: 80px;
			padding-left: 40px;
		}
		li{
			width: 200px;
			height: 50px;
			background-color: yellow;
		}
		.one,.two{margin-top: 40px;}
	</style>
</head>
<body>
	<ul>
		<li>HTML</li>
		<li class="one">CSS</li>
		<li class="two">JavaScript</li>
	</ul>
</body>
</html>

2-7 盒子计算

在这里插入图片描述

第3章 盒子模型的应用

3-1 display属性

在这里插入图片描述
在这里插入图片描述

3-2 编程练习

在这里插入图片描述

<!DOCTYPE html>
<html>
<head>
	<title>3</title>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
	<style type="text/css">
		ul{width: 200px;}
		li{display: none;}
		ul:hover li{display: inline-block;}
	</style>
</head>
<body>
	<ul>
		<h2>家电</h2>
		<li>冰箱</li>
		<li>空调</li>
		<li>洗衣机</li>
	</ul>
</body>
</html>

3-3 编程练习
<!DOCTYPE html>
<html>
<head>
	<title>3</title>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
	<style type="text/css">
		body,div,.div1,.div2,.div3,.elec,.wash,.clothes,h3,li{margin: 0;padding: 0;}
		.big{
			width: 110px;
			margin: auto;
			border: 1px #CCCCCC solid;
		}
		.div1,.div2,.div3{
			border-bottom: 1px #AAAAAA solid;
		}
		h3{
			background-color: #CCCCCC;
			text-align: center;
			padding-top: 2px;
			padding-bottom: 2px;
		}
		li{
			list-style: none;
			margin-bottom: 6px;
			margin-top: 6px;
			display: none;
		}
		.elec,.wash,.clothes{
			background-color: #FFFFFF;
			padding-left:38px;
		}
		.div1:hover .elec li{display: block;}
		.div2:hover .wash li{display: block;}
		.div3:hover .clothes li{display: block;}
	</style>
</head>
<body>
	<div class="big">
		<div class="div1">
			<h3>家电</h3>
			<ul class="elec">
				<li>冰箱</li>
				<li>洗衣机</li>
				<li>空调</li>
			</ul>
		</div>
		<div class="div2">
			<h3>洗护</h3>
			<ul class="wash">
				<li>洗衣液</li>
				<li>消毒液</li>
				<li>柔顺剂</li>
			</ul>
		</div>
		<div class="div3">
			<h3>衣物</h3>
			<ul class="clothes">
				<li>衬衫</li>
				<li>裤子</li>
				<li>卫衣</li>
			</ul>
		</div>
	</div>
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值