如何在<header>元素前面显示div

时间:2015-05-07 13:07:25

标签: css z-index drupal-theming

如何显示标题前面<header>元素之外的div,即z-index更高的div。我曾尝试使用z-index属性,但它似乎无法正常工作。我可以在这里看到我的具体示例:http://www.spabc.com/drupal/我想在标题栏前面的右侧显示徽标。

2 个答案:

答案 0 :(得分:4)

fun_(x=c("a", "b", "c")) 添加到position: relative;

#logo

答案 1 :(得分:1)

添加

position: relative;

#logo会有效。对于z-index,它不适用于默认定位元素。标准position属性为static

  

z-index仅适用于定位元素(位置:绝对,   position:relative,或position:fixed)。

详细了解z-index here

默认元素堆叠

我在MDN上看到了这一点,我想在将它发布到此处之前先完成它。

当元素的属性中没有z-index时,元素按以下顺序堆叠,3是后面最远的元素:

  1. 根元素的背景和边框
  2. 正常流程中的后代阻塞,按外观顺序(以HTML格式)
  3. 后代按照外观(以HTML格式)
  4. 定位元素

    此订单仍然存在规则。

      
        
    • 如果多个重叠对象的position值相同,则按照它们在HTML文档中的位置给出顺序。
    •   
    • 如果未设置position值,则默认为static值。 static元素将始终落后于具有的元素   position值。
    •   

    div {
      font: 12px Arial;
    }
    span.bold {
      font-weight: bold;
    }
    #normdiv {
      height: 70px;
      border: 1px dashed #999966;
      background-color: #ffffcc;
      margin: 0px 50px 0px 50px;
      text-align: center;
    }
    #reldiv1 {
      opacity: 0.7;
      height: 100px;
      position: relative;
      top: 30px;
      border: 1px dashed #669966;
      background-color: #ccffcc;
      margin: 0px 50px 0px 50px;
      text-align: center;
    }
    #reldiv2 {
      opacity: 0.7;
      height: 100px;
      position: relative;
      top: 15px;
      left: 20px;
      border: 1px dashed #669966;
      background-color: #ccffcc;
      margin: 0px 50px 0px 50px;
      text-align: center;
    }
    #absdiv1 {
      opacity: 0.7;
      position: absolute;
      width: 150px;
      height: 350px;
      top: 10px;
      left: 10px;
      border: 1px dashed #990000;
      background-color: #ffdddd;
      text-align: center;
    }
    #absdiv2 {
      opacity: 0.7;
      position: absolute;
      width: 150px;
      height: 350px;
      top: 10px;
      right: 10px;
      border: 1px dashed #990000;
      background-color: #ffdddd;
      text-align: center;
    }
    <div id="absdiv1">
      <br /><span class="bold">DIV #1</span>
      <br />position: absolute;
    </div>
    
    <div id="reldiv1">
      <br /><span class="bold">DIV #2</span>
      <br />position: relative;
    </div>
    
    <div id="reldiv2">
      <br /><span class="bold">DIV #3</span>
      <br />position: relative;
    </div>
    
    <div id="absdiv2">
      <br /><span class="bold">DIV #4</span>
      <br />position: absolute;
    </div>
    
    <div id="normdiv">
      <br /><span class="bold">DIV #5</span>
      <br />no positioning
    </div>

    在浮动对象上没有z-index的堆叠

    对于浮动块,堆叠顺序略有不同。浮动块放置在非定位块和定位块之间:

    1. 根元素的背景和边框
    2. 正常流程中的后裔阻挡,按外观顺序(in HTML)
    3. 浮动块
    4. 正常流程中的内联后代
    5. 后代按照外观(以HTML格式)
    6. 定位元素

      div {
        font: 12px Arial;
      }
      span.bold {
        font-weight: bold;
      }
      #absdiv1 {
        opacity: 0.7;
        position: absolute;
        width: 150px;
        height: 200px;
        top: 10px;
        right: 140px;
        border: 1px dashed #990000;
        background-color: #ffdddd;
        text-align: center;
      }
      #normdiv {
        /* opacity: 0.7; */
        height: 100px;
        border: 1px dashed #999966;
        background-color: #ffffcc;
        margin: 0px 10px 0px 10px;
        text-align: left;
      }
      #flodiv1 {
        opacity: 0.7;
        margin: 0px 10px 0px 20px;
        float: left;
        width: 150px;
        height: 200px;
        border: 1px dashed #009900;
        background-color: #ccffcc;
        text-align: center;
      }
      #flodiv2 {
        opacity: 0.7;
        margin: 0px 20px 0px 10px;
        float: right;
        width: 150px;
        height: 200px;
        border: 1px dashed #009900;
        background-color: #ccffcc;
        text-align: center;
      }
      #absdiv2 {
        opacity: 0.7;
        position: absolute;
        width: 150px;
        height: 100px;
        top: 130px;
        left: 100px;
        border: 1px dashed #990000;
        background-color: #ffdddd;
        text-align: center;
      }
      <div id="absdiv1">
        <br /><span class="bold">DIV #1</span>
        <br />position: absolute;
      </div>
      
      <div id="flodiv1">
        <br /><span class="bold">DIV #2</span>
        <br />float: left;
      </div>
      
      <div id="flodiv2">
        <br /><span class="bold">DIV #3</span>
        <br />float: right;
      </div>
      
      <br />
      
      <div id="normdiv">
        <br /><span class="bold">DIV #4</span>
        <br />no positioning
      </div>
      
      <div id="absdiv2">
        <br /><span class="bold">DIV #5</span>
        <br />position: absolute;
      </div>

相关问题