Patryk Dąbrowski
Patryk Dąbrowski

Reputation: 177

Menu with position absolute is hidden under other element

I have hamburger menu and when I click that it pushes a content to down. I want to prevent it so I've added to active class position: absolute, but then menu is hidden under other element. I tried to use z-index but it doesnt work for this. What am I doing bad?

Here is a codepen https://codepen.io/anon/pen/dEbgvJ

body,
html {
  margin: 0;
  padding: 0;
  font-family: Arial,
    Helvetica,
    sans-serif;
}

ul {
  padding-left: 0;
}

* {
  box-sizing: border-box;
}

h1 {
  margin: 0;
}

.page-header {
  background-color: #87509c;
  width: 100%;
  height: 80vh;
}

.navbar {
  font-size: 18px;
  background: #87509c;
  padding-bottom: 10px;
}

.main-nav {
  list-style-type: none;
  display: none;
}

.nav-links {
  text-decoration: none;
  color: #ffffff;
  text-transform: uppercase;
  font-family: Arial;
  font-size: 16px;
}

.main-nav li {
  text-align: center;
  margin: 15px auto;
}

.navbar-toggle {
  position: absolute;
  top: 22px;
  right: 20px;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.8);
  font-size: 24px;
}

.active {
  display: block;
  position: absolute;
  left: 0;
  right: 0;
  z-index: 100;

}

.logo {
  margin-left: 10px;
  margin-top: 10px;
}

@media screen and (min-width: 768px) {
  .page-header {
    display: flex;
    justify-content: space-around;
    background-color: #87509c;
    width: 100%;
    height: 600px;
  }

  .navbar {
    display: flex;
    justify-content: space-between;
    padding-bottom: 0;
    height: 70px;
    align-items: center;
    width: 1000px;
  }

  .main-nav {
    display: flex;
    margin-right: 30px;
    flex-direction: row;
    justify-content: flex-end;

  }

  .main-nav li {
    margin: 0;
  }

  .nav-links {
    margin-left: 40px;
  }

  .navbar-toggle {
    display: none;
  }

  .nav-links:hover {
    color: rgba(255, 255, 255, 1);
  }
}

.content-container {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  height: 300px;
}

.header-text {
  font-size: 16px;
  text-align: center;
  color: #fff;
  font-weight: 600;
  width: 200px;
  display: block;
  margin: 0 auto;
}

.button-work {
  font-size: 15px;
  font-weight: 300;
  border-radius: 3px;
  color: #fff;
  text-transform: uppercase;
  margin: 0 auto;
  display: block;
  border: none;
  height: 35px;
  width: 150px;
  background: #EB7D4B;
}

Upvotes: 0

Views: 511

Answers (3)

ATIQ UR REHMAN
ATIQ UR REHMAN

Reputation: 448

In li class you add float right property of css:

.main-nav li {
  float:right;
  text-align: center;
  margin: 15px auto;
  }

it works for your problem.

Upvotes: 0

Taras Hrabets
Taras Hrabets

Reputation: 26

Just add background color for open menu for mobile devices

@media screen and (max-width: 768px) {
  .main-nav.active {
    background: red;
  }
}

Upvotes: 1

Haval B Aziz
Haval B Aziz

Reputation: 51

The menu is not hidden, you don't have a background color to it so it's transparent. and the text is white so it will be hard to see. So just add a background color to .man_nav class and you should be good.

Upvotes: 1

Related Questions