web第三周作业(1)探究总结relative、fixed、absolute三种定位的特性和共性

HTML

<!DOCTYPE>
<html>
<head>
    <title>实验探究relative</title>
    <link rel="stylesheet" href="实验样式.css">
</head>
<body>
<div class="box" id="one">One</div>
<div class="box" id="two">Two</div>
<div class="box" id="three">Three</div>
<div class="box" id="four">Four</div>
</body>
</html>

CSS

.box {
  display: inline-block;
  width: 100px;
  height: 100px;
  background: red;
  color: black;
}

#two {
  position: relative;
  top: 20px;
  left: 20px;
  background: blue;
}

三种定位的不同效果图:

 

 

 

relative定位分析:

在计算机定位时,图片显示应该在它的默认位置上进行偏移,top和left属性定义了图片显示的偏移量,在该代码示例中则表示在默认的位置上纵向向下偏移20px,向左横向偏移20px。

fixed和absolute定位分析:

顾名思义,absolute是用来对容器进行绝对定位的,它完全可以抛弃容器原来的位置,放在页面上任意位置,游离在文档页面上,而fixed的属性的定位方式与absolute相同,但fixed一般不用于计算机,一般仅限于打印或者其他媒介显示上进行绝对定位,例如用于广告。

 

absolute同时具有覆盖功能:

CSS

.box {
  display: inline-block;
  width: 100px;
  height: 100px;
  color: white;
}
#one {
  position: absolute;
  top: 20px;
  left: 20px;
  background: red;
}
#two {
  position: absolute;
  top: 40px;
  left: 40px;
  background: black;
}
#three {
  position: absolute;
  top: 60px;
  left: 60px;
  background:yellow;
}
#four {
  position: absolute;
  top: 80px;
  left: 80px;
  background: blue;
}

后出现的图片会覆盖先前出现的图片。

 

转载于:https://www.cnblogs.com/duxingrui-99/p/9685628.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值