6

I have this responsive hamburger nav that is currently pushing down the content below it. Is there a way to get it to just hover over the content instead? I have tried so many things, nothing that I am doing works but I'm not an expert. Any help is much appreciated! Thanks!

jsfiddle here

<nav class="header">
      <input class="menu-btn" type="checkbox" id="menu-btn" />
      <label class="menu-icon" for="menu-btn"><span class="navicon"></span></label>
      <ul class="menu">
        <li><a href="#work">Our Work</a></li>
        <li><a href="#about">About</a></li>
        <li><a href="#careers">Careers</a></li>
        <li><a href="#contact">Contact</a></li>
      </ul>
    </nav>
<figure id="main-img"></figure>

figure#main-img {
    width: 100%;
    position: relative;
    overflow: hidden;
    border-top: 1px solid #000000;
    border-bottom: 1px solid #000000;
    z-index: 10;
  height: 200px;
  background-color: red;
}
nav.header {
    background-color: silver;
  width: 100%;
  float: left;
  overflow: hidden;
}
.table {
    display: table;   
    margin: 0 auto;
}
.header ul {
    list-style: none; 
    position: relative; 
    float: left; 
    display: block; 
    left: 50%;
    max-width: 1200px;
    margin: 0;
    padding: 0;
}
.header ul li {
    position: relative; 
    right: 50%;
    /*float: left; 
    display: inline-block;*/ 
}
.header li a {
    display: block;
    padding: 1em;
    text-decoration: none;
    color: #000000;
}
.header li a:hover {
    background-color: #B5B5B5;
}
.header .menu {
    clear: both;
    max-height: 0;
    transition: max-height .2s ease-out;
}
.header .menu-icon {
    cursor: pointer;
    display: inline-block;
    float: right;
    padding: 28px 20px;
    position: relative;
    user-select: none;
}
.header .menu-icon .navicon {
    background: #333;
    display: block;
    height: 2px;
    position: relative;
    transition: background .2s ease-out;
    width: 18px;
}
.header .menu-icon .navicon:before, .header .menu-icon .navicon:after {
    background: #333;
    content: '';
    display: block;
    height: 100%;
    position: absolute;
    transition: all .2s ease-out;
    width: 100%;
}
.header .menu-icon .navicon:before {
    top: 5px;
}
.header .menu-icon .navicon:after {
    top: -5px;
}
.header .menu-btn {
    display: none;
}
.header .menu-btn:checked ~ .menu {
    max-height: 240px;
}
.header .menu-btn:checked ~ .menu-icon .navicon {
    background: transparent;
}
.header .menu-btn:checked ~ .menu-icon .navicon:before {
    transform: rotate(-45deg);
}
.header .menu-btn:checked ~ .menu-icon .navicon:after {
    transform: rotate(45deg);
}
.header .menu-btn:checked ~ .menu-icon:not(.steps) .navicon:before, .header .menu-btn:checked ~ .menu-icon:not(.steps) .navicon:after {
    top: 0;
}

@media only screen and (min-width: 750px) {
.header li {
    float: left;
}
.header li a {
    padding: 20px 30px;
}
.header .menu {
    clear: none;
    /*float: right;*/
    max-height: none;
}
.header .menu-icon {
    display: none;
}
}

@media only screen and (max-width: 750px) {
.header li a {

    background-color: Silver;
    opacity: 0.9;
}
.header ul li {
    border-bottom: 1px solid #000000;
    color: #000;
}
.header ul li:first-child {
    border-top: 0px solid #000000;
}
.header ul {
    width: 100%;

}
}
@media only screen and (max-width: 480px) {
nav.header {

}
}
Kim
  • 1,175
  • 2
  • 10
  • 21
  • Checkout http://stackoverflow.com/questions/2941189/how-to-overlay-one-div-over-another-div You need to change `position:` and `z-index:` – Puddler Apr 18 '16 at 02:51

1 Answers1

3

Code (only the relevant css, the html did not change) from the JSFiddle in case it stops working:

body {
  width:100%;
  margin:0;
}

figure#main-img {
    width: 100%;
    position: relative;
    float:left;
    overflow: hidden;
    border-top: 1px solid #000000;
    border-bottom: 1px solid #000000;
    height: 300px;
    background-color: red;
    margin:58px 0 0 0;
}

nav.header {
  background-color: silver;
  opacity: 0.75;
  position: absolute;
  width: 100%;
  top:0;
  z-index:10;
  float: left;
  margin:0;
  overflow:hidden;
}
.header .menu-icon {
  padding: 28px 20px;
}

here is a JSFiddle you can work with.

nav.header {
  background-color: silver;
  position: absolute;
  width: 100%;
  top:0;
  z-index:10;
  float: left;
  margin:0;
  overflow:hidden;
}

Here you can see that I set the position to be absolute, set it to the top and then z-index is a larger number than the default.

Hope it helped, Andrew

Andrew Adam
  • 1,572
  • 9
  • 22
  • Thank You! Now what is happening is the nav bar is overlapping the figure below it. How can I get the figure to be below the nav instead of under it? https://jsfiddle.net/kimwild/6obpjnzs/6/ – Kim Apr 19 '16 at 02:06
  • 1
    https://jsfiddle.net/6obpjnzs/10/ <--- Your vertical padding on the .header .menu-icon is 28px which will create a 56px height for the header on top. I added a margin-top:58px (56px + twice the 1px black border) to your figure. This way it stays responsive and works like a charm. – Andrew Adam Apr 19 '16 at 02:25
  • Great! Thank you so much for helping me with this! – Kim Apr 20 '16 at 18:12
  • I am glad it worked, I added the jsfiddle code to the answer to make sure it is available for future visitors. – Andrew Adam Apr 21 '16 at 12:58