位置固定重叠html

时间:2018-03-08 18:39:37

标签: javascript jquery html css

我正在创建一个网站,我希望在向下滚动时修复菜单栏。 我设法做到了这一点,我的问题是我在页面上放了一条垂直线(div的边框),并且该线位于菜单栏的顶部。
我的问题是。为什么要这样做,我该如何解决?

这是网站:https://jsfiddle.net/wo8exk5f/4/

Image



$(document).ready(function () {
    
    $('.button').hover(function () {
        $(this).animate({
                "color": "black",
                "backgroundColor": "#E9A5AF"
        }, 400);
        }, function () {
            $(this).animate({
                "color": "black",
                "backgroundColor": "white"
            }, 400);
        }
    );

    $('#header')
        .css('opacity', 0)
        .slideDown('slow')
        .animate(
            { opacity: 1 },
            { queue: false, duration: 'slow' }
          );
    

          $("#lineOne").animate({
            left: "0%",opacity: '0.4'
        }, 1000);

        $("#lineTwo").animate({
            left: "0%",opacity: '0.4'
        }, 1000);
});

@font-face {
    font-family: myFont;
    src: url(PlayfairDisplay-Regular.ttf);
}

li {
    text-decoration: none;
    list-style-type: none;
    display: inline;
    padding: 10px;
    margin: 5px;
    margin-left: 20px;
    border-radius: 5px;
    font-size: 25px;
}

img {
    width: 100px;
    height: 100px;
    float: left;
    margin-left: 10px;
}
li:last-child {
    margin-right: 40px;
}

ul {
    float: right;
}

body {
    width: 100%;
    height: 100%;
    padding: 0px;
    margin: 0px;
    font-family: myFont;
}

#header {
    z-index: 1;
    position: fixed;
    width: 100%;
    box-shadow: 0 2px 5px gray;
    display: none;
    margin: auto;
    height: 106px;
    top:0;
    left: 0;
    right: 0;
}

#headerTable {
    width: 100%;
}
#container {
    position: relative;
    width: 99%;
    top: 130px;
    left: 8px;
    height: 80%;

}

.innerContainer{
    display: inline-block;
    position: relative;
    width: 33%;
    height: 80%;

}

#lineOne{
    position: relative;
    width: 40%;
    border-right: 2px solid gray;
    height: 1500px;
    opacity: 0;
    left: -50%;

}

#lineTwo{
    position: relative;
    width: 60%;
    border-right: 2px solid gray;
    height: 1500px;
    opacity: 0;
    left: 150%;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="header">
<table id="headerTable">
  <tr>
    <th> <img src="logo.jpg"> </th>
    <th> <ul>
      <li class="button">Home</li>
      <li class="button">Asztalfoglalás</li>
      <li class="button">Galéria</li>
      <li class="button">Térkép</li>
      <li class="button">Elérhetőség</li>
    </ul>
    </th>
  </tr>
</table>
</div>

<div id="container">
  <!-- 1 -->
  <div class="innerContainer">
      <div id="lineOne">

      </div>
  </div>
  <!-- 2 -->
  <div class="innerContainer">

  </div>
  <!-- 3 -->
  <div class="innerContainer">
      <div id="lineTwo">

      </div>
  </div>
</div>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:1)

菜单栏是透明的。你必须添加一个背景。

#header {
    background-color: #fff; // now it won't overlap
    z-index: 1;
    position: fixed;
    width: 100%;
    box-shadow: 0 2px 5px gray;
    display: none;
    margin: auto;
    height: 106px;
    top: 0;
    left: 0;
    right: 0;
}

答案 1 :(得分:0)

        #container {
          position: relative;
          width: 99%;
          top: 130px;
          left: 8px;
          height: 80%;
          z-index: 1;
        }

        #lineOne{
            position: relative;
            width: 40%;
            border-right: 2px solid gray;
            height: 1500px;
            opacity: 0;
            left: -50%;
            z-index: 1;
        }

        #lineTwo{
            position: relative;
            width: 60%;
            border-right: 2px solid gray;
            height: 1500px;
            opacity: 0;
            left: 150%;
            z-index: 1
        }
        #header {
            z-index: 2;
            position: sticky;
            width: 100%;
            box-shadow: 0 2px 5px gray;
            margin: auto;
            height: 106px;
            top:0;
            left: 0;
            right: 0;
            background-color: red;
        }

position : relative更改为sticky,并将行和容器css更改为z-index:1,将background-color更改为header