position: relative; 用法top bottom用法

本文通过HTML代码示例展示了<div>元素中使用relative定位结合top和bottom属性如何影响内容位置。relative定位允许在不脱离文档流的情况下移动内部内容,是绝对定位的一个简化形式。
摘要由CSDN通过智能技术生成
 <div style="height: 100px;width: 100px;background-color: yellow;">2</div>
    <div style="height: 100px;width: 100px;background-color: red;">3</div>
    <div style="height: 100px;width: 100px;background-color: blue;">4</div>

 

我们看看加上top会怎么样

    <div style="height: 100px;width: 100px;background-color: yellow;">2</div>
    <div style="height: 100px;width: 100px;background-color: red;position: relative;top: 80px;">3</div>
    <div style="height: 100px;width: 100px;background-color: blue;">4</div>

看看Bottom

    <div style="height: 100px;width: 100px;background-color: yellow;">2</div>
    <div style="height: 100px;width: 100px;background-color: red;position: relative;bottom: 80px;">3</div>
    <div style="height: 100px;width: 100px;background-color: blue;">4</div>

 

//如果button和top都写只会留下top的效果

 总结relative也可以使用top bottom,且自身盒子可以达到在不脱离文档流的情况下,移动内部内容的位置,可以说是绝对定位的一种简单版本

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值