Reputation: 109
I'm making a website and I want the menu bar to be fixed when you scroll down.
I managed to do that my problem is that I've put a vertical line on the page(border of a div) and the line is on top of the menu bar.
My question is. Why is it doing that and how can I fix it?
here is the website: https://jsfiddle.net/wo8exk5f/4/
$(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>
Upvotes: 1
Views: 29
Reputation: 680
#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;
}
change position : relative
to sticky
and change lines and containers css to z-index:1
and some background-color
for header
.
Upvotes: 0
Reputation: 1405
The menu bar is transparent. You have to add a background to it.
#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;
}
Upvotes: 1