代码之家  ›  专栏  ›  技术社区  ›  Andrew

cssz-index问题:可以在Firefox中使用,但不能在Safari中使用?

  •  0
  • Andrew  · 技术社区  · 14 年前

    我试图在覆盖图的顶部显示一个特定的表行。它在Firefox中工作,但不是Safari。我不明白这怎么可能,因为Firefox和Safari通常呈现相同的类型。

    <body>
    
        <style>
            .overlay {
                position:absolute;
                width:100%;
                height:100%;
                background:#000;
                opacity: 0.5;
            }
        </style>
    
        <table>
            <tr style="position:relative; z-index:1000; background:#fff;">
                <td>show this one on top</td>
            </tr>
            <tr>
                <td>Show these below</td>
            </tr>
            <tr>
                <td>Show these below</td>
            </tr>
            <tr>
                <td>Show these below</td>
            </tr>
        </table>
    
        <div class="overlay"></div>
    
    </body>
    

    是什么导致了Safari和Firefox之间的这种差异?

    2 回复  |  直到 14 年前
        1
  •  4
  •   Andrew    14 年前

    CSS 2.1 specifications :

    我假设Firefox以一种方式实现它,WebKit以另一种方式实现它,这两种方式都是正确的,因为它是未定义的。这个故事的寓意不是在表元素上指定位置。

    div

    <table>
        <tr>
            <td>
                <div style="position:relative; z-index:1000;">
                    Displays on top in both Safari and Firefox
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div style="position:relative; z-index:1000;">
                    Displays on top in both Safari and Firefox
                </div>
                <span class="overlay"></span>
            </td>
        </tr>
        <tr>
            <td>Displays below overlay</td>
        </tr>
        <tr>
            <td>Displays below overlay</td>
        </tr>
        <tr>
            <td>Displays below overlay</td>
        </tr>
    </table>
    
        2
  •  -1
  •   matthughes404    14 年前

    Safari和Firefox使用不同的呈现引擎,这就解释了为什么在本例中它们的行为不同。Safari使用WebKit,而Firefox使用Gecko。