html - 为什么导航的框阴影没有显示?

标签 html css

我想让页眉的导航有一个框阴影。然而,盒子阴影似乎被我放在它下面的轮播隐藏了。我放置了#carousel 的所有子项的 z-index,但框阴影仍然没有显示。

(页面片段)enter image description here

这是当我给它 margin-top: 40px 时将#carousel 向下推时发生的情况;

(另一页片段)enter image description here

HTML

<header>

                <nav>

                    <div class="container">

                        <h1><a href="#"><img src="images/logo.png" alt="" id="logo"></a></h1>
                        <h1 id="NHS"><a href="#">Newport High School</a></h1>

                        <ul id="nav">
                            <li><a href="#">Home</a></li>
                            <li><a href="#">About</a></li>
                            <li><a href="#">Students</a></li>
                            <li><a href="#">Parents</a></li>
                            <li><a href="#">Activities & Atletics</a></li>
                            <li><a href="#">Resources</a></li>
                        </ul>

                    </div><!--container---> 

                </nav>

            </header><div id="carousel">                        
                <div class="inner">
                    <ul>
                        <li><img src="images/example-slide-1.jpg" alt="Fish"></li>
                        <li><img src="images/example-slide-2.jpg" alt="Elephant"></li>
                        <li><img src="images/example-slide-3.jpg" alt="Giraffe"></li>
                        <li><img src="images/example-slide-4.jpg" alt="Fish"></li>
                    </ul>
                </div>                                      
            </div>

CSS

/* - - - header - - - */

header {
    background: rgb(30,27,27); /* Old browsers */

    background: -moz-linear-gradient(top,  rgba(30,27,27,1) 0%, rgba(2,2,2,1) 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(30,27,27,1)), color-stop(100%,rgba(2,2,2,1))); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top,  rgba(30,27,27,1) 0%,rgba(2,2,2,1) 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top,  rgba(30,27,27,1) 0%,rgba(2,2,2,1) 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top,  rgba(30,27,27,1) 0%,rgba(2,2,2,1) 100%); /* IE10+ */
    background: linear-gradient(to bottom,  rgba(30,27,27,1) 0%,rgba(2,2,2,1) 100%);  


    box-shadow:           0px 3px 15px rgba(50, 50, 50, .7);
        -webkit-box-shadow: 0px 3px 15px rgba(50, 50, 50, .7);
        -moz-box-shadow:    0px 3px 15px rgba(50, 50, 50, .7);

    z-index: 1000;

} 

    header h1, header li {
        float: left;
    }

    header a {
        color: #A1A1A1 ;
        font-family: arial, helvetica, verana, sans-serif;
    }

        header a:hover {
            color: #A1A1A1;
            text-decoration: none;
        }

#logo {
    width: 50px;
}

#NHS {
    margin: 1.8% 0 0 2%;
    font-size: 1.2em;
    text-transform: uppercase;
}

    #NHS a {
        color: #F6F6F6;
        letter-spacing: 2px;
    }

#nav {
    float: right;
    margin: 3% 0 0 0;

}

    #nav li {
        margin-right: 20px;
        padding: 0;
    }

    #nav li:last-of-type {
        margin-right: 0px;
    }

        #nav a {
         font-size: .8em;
         text-transform: uppercase;
         padding-top: 3px;
         font-weight: 400;
        }

        #nav a:hover {
            border-top: 1px dotted #C41D0E;
        }





/* - - - carousel - - - */

#carousel {
    margin: 40px 0 0 0;
    width: 100%;
    overflow: hidden;
    z-index: -999;
}

    #carousel .inner {
        box-sizing: border-box;
        margin-left: -50px;
        z-index: -5000;
    }

        #carousel ul {
            width: 60000px;
            height: 480px;
            z-index: -5000;
        }

            #carousel li {
                height: 480px;
                float: left;
                overflow: hidden;
                z-index: -5000;
            }

                #carousel img {
                    text-align: center;
                    width: 1375px;
                    height: auto;
                    z-index: -5000;
                }

最佳答案

记住 z-index 只适用于定位元素。因此,您的轮播和 header 都需要有一个 position 值而不是 static,然后您可以为 header 指定一个更高的 z-index。这样 box-shadow 就会正确显示在旋转木马上方。

关于html - 为什么导航的框阴影没有显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15983325/

相关文章:

java - 我如何调用 DaisyDiff 来比较两个 HTML 文件?

html - 将 CSS 应用到带有类的 div 内的所有元素是级联的还是显式的?

HTML/CSS 对齐 div 中的多个元素

html - Prestashop 为特定类别创建自定义布局

html - 响应式 CSS 表格

javascript - html5 拖放上传在 chrome 中损坏

html - 将鼠标悬停在其父元素上时更改插入符号按钮

php - 警告 : session_start() [function. session 启动] Wordpress 仪表板上的错误

python - 将 HTML 转换为纯文本并保留基本格式

html - 使绝对div高度为100%