html - 带有 z-index 的子菜单不想覆盖内容

标签 html css navigation

由于某些未知原因,z-index 似乎不起作用。我尝试制作子菜单。即第二个酒吧。查看它无法执行的#content....

http://jsfiddle.net/PaD2v/

HTML

<html>
    <head>
        <title>Мэрия Skrillax-RP</title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <link rel="stylesheet" type="text/css" href="master.css" />
        <link rel="stylesheet" type="text/css" href="http://meyerweb.com/eric/tools/css/reset/reset.css" />
        <link href='http://fonts.googleapis.com/css?family=Poiret+One&subset=cyrillic' rel='stylesheet' type='text/css'>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
        <script type="text/javascript" src="master.js"></script>
    </head>
    <body>
        <div id="wrapper">
            <div id="banner"><img src="http://i.imgur.com/f2EWgQP.png?1"><p id="banner text"></div>
            <ul id="navigation">
                <li><a href="#">Главная Страница</a></li>
                <li><a href="#">Задачи</a>
                    <ul class="submenu">
                        <li><a href="">Охрана</a></li>
                        <li><a href="">Министерство Обороны</a></li>
                        <li><a href="">Министерство Юстиций</a></li>
                        <li><a href="">Министерство Культуры</a></li>
                        <li><a href="">Министрество</a></li>
                    </ul>
                </li>
                <li><a href="#">Список Сотрудников</a>
                    <ul class="submenu">
                        <li><a href="">Hello</a></li>
                        <li><a href="">Hello2</a></li>
                    </ul>
                </li>
                <li><a href="#">Вакансии</a></li>
                <li><a href="#">Авторизация</a></li>
            </ul>
            <div id="content">
                <p>Hello! Welcome to the www.mayor.freeiz.com!<br><br> Currently I am working on adding different types of information</p>
            </div>
        </div>
            <div id="footer">Hello</div>
    </body>
</html>

CSS

html {
    height:;
}
body {
    background-image: url("http://www.gtagaming.com/images/potd/200604/10501.jpg");
    background-attachment: fixed;
    background-size: 100% 100%;
    height:100%;
}
#wrapper {
    width:1024px;
    min-height: 100%;
    margin:0 auto;
}
#banner {
    height:216px;
}
#navigation {
    position:relative;
    list-style-type:none;
    font-size: 18px;
    background-color: orange;
    font-family: 'EB Garamond', serif;
    opacity:0.8;
    z-index: 15000001;

}

#navigation>li {
    float:left;
    
}
#navigation a {
    display:block;
    padding:10px 10px;
    color:white;
    font-weight: bold;
    width:183.81px;
    height:40px;
    text-align: center;
    background-color: blue;
    border-left:1px solid black;
    text-decoration:none;
}
#navigation a:hover {
    background-color:white;
    color:blue;
    border-top:3px solid red;
    opacity:0.9999;
    margin-bottom: -3px;
}
#banner h1 {
    font-size: 20px;
    text-align: center;
    position: relative;
    top: 1024px;
}
#content {
    position:relative;
    height:500px;
    background-color:white;
    opacity:0.9;
    clear: both;
    z-index:1;
}

#content p{
    position:relative;
    top:6px;
    font-size: 30px;
    z-index:1;
}

#footer {
    vertical-align: bottom;
    background-color: orange;
    width:1024px;
    height:50px;
    margin:0 auto;
}

.submenu {
    display:none;
    position:relative;
    
}
.submenu li {
    border-top: 2px solid black;
}
#navigation li:hover .submenu {
    display:block;
    z-index:99999999999999999999999999999999999999;
}

最佳答案

不要在 .submenu 中使用 relative 位置,而是使用 absolute 位置

CSS

.submenu {
    display:none;
    position:absolute;  
}

工作 demo

关于html - 带有 z-index 的子菜单不想覆盖内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15736575/

相关文章:

android - onUpdateNavigationState() 错误

html - Google 字体在 5 个浏览器中的 2 个中不起作用

html - flex 布局溢出外容器

html - 如何让基于 CSS <li> 的导航栏居中?

css - 如何在渲染前获取 react 组件的大小(高度/宽度)?

navigation - 如何在 UWP 托管应用程序 (JS) 中完全禁用后退按钮

javascript - 创建表格单元格值数组 jQuery

html - Adobe Acrobat Reader 背后的 CSS 内容

css - 基于当前屏幕宽度的手写笔(css)计算

html - 如何让导航横跨整个页面