339day(盒子模型和层模型)

本文深入探讨了网页设计中核心的盒子模型概念,包括边框、内边距、内容区域和外边距的组成,以及如何计算实际宽度和高度。同时,详细讲解了绝对定位和相对定位的区别和应用,帮助读者掌握网页布局的关键技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

《2018年9月7日》【连续339天】

标题:盒子模型和层模型;
内容:

早起了。

盒子模型:

<body>
	<!-- 盒子模型 -->
	<!-- 盒子的四大部分:
	盒子的组成部分:
	盒子壁:border
	内边距:padding
	盒子内容:width+height;

	margin +border +padding +(content) -->
	<div>香菜!</div>
</body>
div{
	width: 100px;
	height: 100px;
	background-color: red;
	border: 10px solid black;
	padding: 100px;
	margin: 100px;
}

求可视区宽高:
 

div{
	width: 100px;
	height: 100px;
	background-color: red;
	border: 10px solid black;
	padding: 10px 20px 30px;
	margin: 10px 20px;
}

/*realWidth:160px
realHeight:160px*/

绝对定位:

    <!-- 绝对定位 -->
	<!-- 1.脱离原来位置(层)进行定位 -->
	<div class="demo"></div>
	<div class="box"></div>
*{
	margin: 0;  /*body有初始margin韦8px;*/
	padding: 0;
}
.demo{
	position: absolute;  /*绝对定位;*/
	width: 100px;
	height: 100px;
	background-color: red;
	opacity: 0.5;
}

.box{
	width: 150px;
	height: 150px;
	background-color: green;
}

相对定位:

    <!-- 相对定位 -->
	<!-- 2.保留原来位置进行定位; -->

	<div class="demo"></div>
	<div class="box"></div>
demo{
	position: relative;  /*绝对定位;*/
	left: 100px;
	top:100px;
	width: 100px;
	height: 100px;
	background-color: red;
	opacity: 0.5;
}

.box{
	width: 150px;
	height: 150px;
	background-color: green;
}

<!-- absolute相对于最近的定位父级元素定位,如果没有,相对于文档定位; -->
    <!-- relative相对于自己原来位置定位 -->
	<div class="wrapper">
		<div class="content">
			<div class="box"></div>
		</div>
	</div>
.wrapper{
	margin-left: 100px;
	width: 200px;
	height: 200px;
	background-color: orange;
}

.content{
	margin-left: 100px;
	width: 100px;
	height: 100px;
	background-color: black;
}

.box{
	position: absolute;
	left: 50px;
	width: 50px;
	height: 50px;
	background-color: yellow;
}

 

一般有relative当作基底,absolute定位。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值