【问题标题】:what's z-index and what is it used for? [duplicate]什么是 z-index,它的用途是什么? [复制]
【发布时间】:2015-08-07 18:37:27
【问题描述】:

我正在学习网页设计。我不知道 z-index它是做什么用的... 我正在尝试定位下拉菜单。我读到它对书中的菜单很有用。 如果有人回答我,我将不胜感激。

【问题讨论】:

标签: css z-index


【解决方案1】:

您可以随时查看文档:

z-index 属性指定元素的 z 顺序及其 子孙。当元素重叠时,z-order 决定哪一个 覆盖另一个。 z-index 较大的元素通常覆盖 具有较低元素的元素。

对于定位框,z-index 属性指定:

  • 当前stacking context中box的堆栈层级。

  • 列表项框是否建立本地堆叠上下文。

例子:

.dashed-box {
  position: relative;
  z-index: 1;
  border: dashed;
  height: 8em;
  margin-bottom: 1em;
  margin-top: 2em;
}
.gold-box {
  position: absolute;
  z-index: 3;
  /* put .gold-box above .green-box and .dashed-box */
  background: gold;
  width: 80%;
  left: 60px;
  top: 3em;
}
.green-box {
  position: absolute;
  z-index: 2;
  /* put .green-box above .dashed-box */
  background: lightgreen;
  width: 20%;
  left: 20em;
  top: -25px;
  height: 7em;
  opacity: 0.9;
}
<div class="dashed-box">Dashed box
  <span class="gold-box">Gold box</span>
  <span class="green-box">Green box</span>
</div>

z-index

【讨论】:

    猜你喜欢
    • 2011-09-03
    • 1970-01-01
    • 1970-01-01
    • 2010-09-27
    • 2011-12-17
    • 2010-11-21
    • 1970-01-01
    • 2016-03-28
    相关资源
    最近更新 更多