【问题标题】:z-index doesn't work as I expected inside ion-slidesz-index 在 ion-slides 中无法正常工作
【发布时间】:2016-07-31 07:23:57
【问题描述】:

我有两个使用ion-slides 组件的滑块,并且我创建了一个带有两个按钮(导航按钮)的页脚。到那里为止。

但是...我在其中一个滑块中有一个表单,所以当我关注 input text 元素时,virtual keyboard 打开并向上移动页脚,将其放在表单前面。

我知道 hide-on-keyboard-open 类,但这不是中间的(你可以看到页脚是如何放在表单前面几秒钟的),所以我想到了使用 z-index

所以,当footer 向上移动时,它会隐藏在表单下。但我无法让它工作。

也许有人可以帮我解决这个问题?

我的意图是当他们有联系时,绿色块隐藏在蓝色块下......我创建了一个代码笔来显示这个问题:https://codepen.io/anon/pen/QEBxRK?editors=1111

(由于无法在台式电脑上打开虚拟键盘,可以调整页面高度看看z-index不起作用)

问候!

【问题讨论】:

  • z-index 需要设置为.footerTest 的同级元素,即<ion-slides options="sliderOptions" slider="slider"> 元素。像现在这样将其设置为孩子是行不通的
  • 感谢您的评论!哦...所以我无法做出我描述的问题?如果我将 z-index 设置为 ion-slides,我将永远看不到页脚。顺便说一句,您能否在答案中转换您的评论?

标签: css ionic-framework slider z-index swiper


【解决方案1】:

z-index 需要设置为.footerTest 的同级元素<ion-slides options="sliderOptions" slider="slider">。

一种选择是将.footerTest 移动到幻灯片中。

下面的示例显示了z-index 如何应用于元素及其子元素。

源:https://developer.mozilla.org/en/docs/Web/CSS/z-index

.dashed-box { 
  position: relative;
  z-index: 3;
  border: dashed;
  height: 8em;
  margin-bottom: 1em;
  margin-top: 2em;
}
.gold-box { 
  position: absolute;
  z-index: 2;
  background: gold;
  width: 65%;
  left: 60px;
  height: 7em;
  top: 3em;
}
.green-box { 
  position: absolute;
  z-index: 1;
  background: lightgreen;
  width: 20%;
  left: 65%;
  top: -25px;
  height: 8em;
  opacity: 0.9;
}
.red-box { 
  position: relative;
  z-index: 0;
  background: red;
  height: 8em;
  margin-bottom: 1em;
  margin-top: -4em;
  text-align: right;
}
<div class="dashed-box">Dashed box
  <span class="gold-box">Gold box</span>
  <span class="green-box">Green box</span>
</div>
<div class="red-box">Red box</div>

但是,如果您省略 dashed-box 上的 z-index 并使用负值,就像在蓝色框上一样,蓝色会在它们下方。

.dashed-box { 
  position: relative;
  /* z-index: 3; */
  border: dashed;
  height: 8em;
  margin-bottom: 1em;
  margin-top: 2em;
}
.gold-box { 
  position: absolute;
  z-index: 2;
  background: gold;
  width: 65%;
  left: 60px;
  height: 7em;
  top: 3em;
}
.green-box { 
  position: absolute;
  z-index: 1;
  background: lightgreen;
  width: 20%;
  left: 65%;
  top: -25px;
  height: 8em;
  opacity: 0.9;
}
.blue-box { 
  position: absolute;
  z-index: -1;
  background: lightblue;
  width: 20%;
  left: 25%;
  top: -25px;
  height: 18em;
  opacity: 0.9;
}
.red-box { 
  position: relative;
  z-index: 0;
  background: red;
  height: 8em;
  margin-bottom: 1em;
  margin-top: -4em;
  text-align: right;
}
<div class="dashed-box">Dashed box
  <span class="gold-box">Gold box</span>
  <span class="green-box">Green box</span>
  <span class="blue-box">Blue box</span>
</div>
<div class="red-box">Red box</div>

【讨论】:

  • 非常感谢。你可以用这个选项更新我的 codepen 吗?
  • @MartaGom 我很乐意这样做,尽管我没有时间深入研究滑块脚本来查看哪些元素获得 z-index。我希望你能理解这一点,我的回答帮助你克服了这个问题,即使你必须自己做艰苦的工作:)
猜你喜欢
  • 2017-09-29
  • 2012-01-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-04
  • 1970-01-01
  • 1970-01-01
  • 2022-01-23
相关资源
最近更新 更多