DIV(CSS 定位)

本文介绍了如何使用CSS的relative和absolute属性进行元素定位,并通过TOP、LEFT等属性精确控制位置。此外,还讲解了如何利用Z-INDEX实现层叠效果,使某些元素覆盖在其他元素之上。
<div style="position: relative;width:800px;height: 300px;background-color: gainsboro;border:1px solid red;margin: 0 auto">
    <div style="position: absolute;width:100px;height: 100px;bottom: 0;left: 0;background-color: brown">
    </div>
</div>


<div style="position: relative;width:800px;height: 300px;background-color: gainsboro;border:1px solid red;margin: 0 auto">
    <div style="position: absolute;width:100px;height: 100px;top: 0;right: 0;background-color: brown">
    </div>
</div>


<div style="position: relative;width:800px;height: 300px;background-color: gainsboro;border:1px solid red;margin: 0 auto">
    <div style="position: absolute;width:100px;height: 100px;bottom:0;background-color: brown">
    </div>
</div>

当需要下层DIV在上层DIV中定位时,上层DIV使用relative,下层DIV使用absolute.配合TOP,LEFT,RIGHT,BOTTOM定位。

<div style="z-index: 10;position: fixed;top: 50%;left:50%;margin-top:-200px;margin-left:-200px;background-color: white;width: 200px;height: 200px;"></div>
<div style="z-index:9;position: fixed;background-color: black;top: 0;bottom:0;right:0;left:0;opacity: 0.5;"></div>
<div style="height: 400px;width: 800px;background-color: darkcyan"></div>

opacity:0.5 --->透明度

Z-INDEX 数据越大,DIV在最顶层。

转载于:https://www.cnblogs.com/GabyGU/p/7786861.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值