在手機自帶瀏覽器遇到的一個關於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;
圖片描述spa

個人解決方法是:code

<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>

我以爲確定還有其餘的解決辦法,一時沒想到,想着向你們學習下,看看其餘的解決辦法blog

相關文章
相關標籤/搜索