【问题标题】:Flexbox: Element shadows doesn't work with order propertyFlexbox:元素阴影不适用于 order 属性
【发布时间】:2014-12-15 20:40:54
【问题描述】:

我正在尝试使用 CSS3 的 flexbox 功能创建一个简单的布局,但我遇到了一个问题:我无法将 nav 元素的阴影放在 main 元素上,即使 nav 元素在后面main

我尝试为此使用order 属性,但我不明白为什么nav 的阴影在main 下方

html {
  height: 100%;
}
body {
  display: flex;
  flex-direction: column;
  height: 100%;
  margin: 0;
}
body >* {
  background-color: #333;
  color: #bdbdbd;
  box-shadow: 0px 0px 10px 2px #000;
  text-shadow: 0 -1px 0 #000;
  padding: 10px;
}
main {
  height: 500px;
  order: 1;
}
nav {
  order: 0;
}
footer {
  order: 2;
}
<main>Main content</main>
<nav>Navigation</nav>
<footer>Footer</footer>

JSFIDDLE

不使用poasition:abosolute 属性是否可以做到这一点(仅适用于弹性盒功能)?

【问题讨论】:

    标签: css flexbox


    【解决方案1】:

    使用z-index 属性按所需顺序堆叠元素。

    nav {
        order:0;
        z-index:2;
    }
    

    这是一个演示:http://jsfiddle.net/Lfaezsek/1/

    【讨论】:

    • 酷。但是为什么 z-index 在这里起作用呢?它应该只适用于非静态定位元素..
    • @boyd 对于弹性项目z-index 将建立一个堆叠上下文,即使position 的计算值是static
    • 很好的问题,the w3c says: Flex items paint exactly the same as inline blocks [CSS21], except that order-modified document order is used in place of raw document order, and z-index values other than auto create a stacking context even if position is static.
    • 很高兴知道。谢谢!
    • 我以前也不知道,很高兴你问。祝你好运!
    猜你喜欢
    • 2017-01-20
    • 1970-01-01
    • 1970-01-01
    • 2015-05-04
    • 1970-01-01
    • 1970-01-01
    • 2015-01-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多