下拉菜单停留在div后面

时间:2018-06-28 19:35:12

标签: html css

我的下拉菜单停留在主div后面或陷在标题内。我弄乱了z-index,但没有帮助。我怎么能知道它是不是标题被捕获,而不是主div隐藏了它。

这是问题的图片:

Stuck dropdown

body {
  margin: 0;
  font-family: arial;
}

button {
  border-style: solid;
  border-color: black;
  border-radius: 5px;
}

a {
  text-decoration: none;
  color: blue;
}

#header {
  overflow: hidden;
  background-color: #FFF;
  position: fixed;
  top: 0;
  width: 100%;
  height: 50px;
  border-bottom: solid;
  border-bottom-color: black;
}

.headerSection {
  float: left;
  width: 33%;
  height: 100%;
  display: table;
  text-align: center;
}

.headerSection>.headerItem {
  display: table-cell;
  vertical-align: middle;
}

#asdf {
  position: absolute;
  top: 0;
  left: 0;
  width: 50px;
  height: 50px;
  border-radius: 0;
  background: #1466C0;
  color: #FFAD01;
  border-bottom: 0;
}

#asdf:hover {
  background-color: #00B2EE;
}

.TOC {
  margin-top: 25px;
  display: none;
  position: absolute;
  background-color: #f9f9f9;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  z-index: 999;
}

.dropdown:hover .TOC {
  display: block;
}

.TOC a {
  float: none;
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
  text-align: left;
}

#main {
  margin-top: 55px;
  z-index: 1;
}
<div id="header">
  <div class="headerSection">
    <div class="dropdown">
      <button class="headerItem" id="asdf">&#9776</button>
      <div class='TOC'>
        <a href='#OS'>OS Information</a>
        <a href='#GI'>General Information</a>
        <a href='#DI'>Domain Information</a>
        <a href='#SUC'>Start-Up Command</a>
        <a href='#shares'>Shares</a>
        <a href='#EV'>Environment Vars</a>
        <a href='#proc'>Processes</a>
      </div>
    </div>
  </div>
  <div class="headerSection">
    <h1 class="headerItem">Windows Audit Script Report</h1>
  </div>
  <div class="headerSection">
    <p class="headerItem" id="aede">Run Time: 2018-06-28 10:11:24.145067</p>
  </div>
</div>
<div id="main">
  <div style='clear:both'></div>

有人对如何解决此问题有任何想法吗?

2 个答案:

答案 0 :(得分:1)

问题是您在#header上设置的overflow: hidden。如果删除,则下拉列表应该可以正常工作。

jsfiddle:https://jsfiddle.net/1du6f928/1/

答案 1 :(得分:1)

发生这种情况是因为标头有溢出:隐藏,您应该删除隐藏的溢出 请检查更改:

body
        {
            margin: 0;
            font-family: arial;
        }
        button
        { 
            border-style: solid;
            border-color: black;
            border-radius: 5px;
        }

        a
        {
            text-decoration: none; 
            color: blue;
        }
        #header
        {
           
            background-color: #FFF;
            position: fixed;
            top: 0;
            width: 100%;
            height: 50px;
            border-bottom: solid;
            border-bottom-color: black;
        }
        .headerSection 
        {
            float: left;
            width: 33%;
            height: 100%;
            display: table;
            text-align: center;
        }
        .hidden-height-header{width:66%; float:left; height:50px; overflow:hidden}
        .hidden-height-header >.headerSection {width:50%}
        .headerSection > .headerItem 
        {
            display: table-cell;
            vertical-align: middle;
        }
        #asdf
        {
            position: absolute;
            top: 0;
            left: 0;
            width: 50px;
            height: 50px;
            border-radius: 0;
            background: #1466C0;
            color: #FFAD01;
            border-bottom: 0;
        }
        #asdf:hover
        {
            background-color: #00B2EE;
        }

        .TOC {
            margin-top: 25px;
            display: none;
            position: absolute;
            background-color: #f9f9f9;
            min-width: 160px;
            box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
            z-index: 999;
        }
        .dropdown:hover .TOC {
            display: block;
        }
        .TOC a {
            float: none;
            color: black;
            padding: 12px 16px;
            text-decoration: none;
            display: block;
            text-align: left;
        }
        #main
        {
            margin-top: 55px;
            z-index: 1;
        }
<body>
    <div id="header">
        <div class="headerSection">
            <div class="dropdown">
                <button class="headerItem" id="asdf">&#9776</button>
                <div class='TOC'>
                    <a href='#OS'>OS Information</a>
                    <a href='#GI'>General Information</a>
                    <a href='#DI'>Domain Information</a>
                    <a href='#SUC'>Start-Up Command</a>
                    <a href='#shares'>Shares</a>
                    <a href='#EV'>Environment Vars</a>
                    <a href='#proc'>Processes</a>
                </div>
            </div>
        </div>
   <div class="hidden-height-header">
        <div class="headerSection">
            <h1 class="headerItem">Windows Audit Script Report</h1>
        </div>
        <div class="headerSection">
            <p class="headerItem" id="aede">Run Time: 2018-06-28 10:11:24.145067</p>
        </div>
        </div>
    </div>
    <div id="main">
        <div style = 'clear:both'></div>

</div></body>