在手机自带浏览器遇到的一个关于position的坑,absolute设置的位置没出现在预期...

结构是这样的

<div class="box">
  <div class="content">something</div>
  <div class="inner"></div>
</div>

样式是这样的

.box {
  position: relative;
  width: 160px;
  height: 160px;
  border: 1px solid #f3f5f7;
}
.content {
  width: 100%;
  height: 40px;
  background-color: #ee0000;
}
.inner {
  position: absolute;
  left: 0;
  bottom: 15px;
  width: 100%;
  height: 40px;
  background-color: #f3f5f7;
}

但是发现在一些浏览器上并没有距离底边15px,而是距离.content的底部15px;
图片描述

我的解决方法是:

<div class="box">
  <div class="content">something</div>
  <div class="inner">
    <div class="set"></div>
  </div>
</div>
<style>
.box {
  position: relative;
  width: 160px;
  height: 160px;
  border: 1px solid #f3f5f7;
}
.content {
  width: 100%;
  height: 40px;
  background-color: #ee0000;
}
.inner {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
}
.set {
  position: absolute;
  left: 0;
  bottom: 15px;
  width: 100%;
  height: 40px;
  background-color: #f3f5f7;
}
</style>

我觉得肯定还有其他的解决办法,一时没想到,想着向大家学习下,看看其他的解决办法

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值