Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What makes the dropdown menu content "stick" to the menu item?

Tags:

html

css

I've almost got my dropdown menu working, but I can't get the dropdown content to appear underneath the head when it's clicked. It's moved off to the side. What's causing that? Is it improperly written position?

Fiddle: https://jsfiddle.net/kiddigit/8sxj3eeg/

  * {
    font-family: garamond;
    line-height: 1.9em;
  }

.dropdownwrapper {
  padding-top: 2px;
}

.dropbtn {
    color: black;
    padding: 13px;
    font-size: 16px;
    border: none;
    cursor: pointer;
}

.dropdown-content {
/*    display: none;*/
    position: absolute;
}

.dropdown-content a {
    color: white;
    padding: 0 27.5px ; 
    text-decoration: none;
    display: block;
    background-color: #3f3f3f;
}

.dropdown-content a:hover {
  color: #a9a9a9;
}

.dropdown:hover .dropdown-content {
    display: block;
}

.dropdown:hover .dropbtn {
    background-color: black;
    color: white;
}


header {    
    border-bottom: 5px solid;
    margin-bottom: 10px;
    overflow: hidden;
}

header ul {   
  float: right;
  list-style-type: none;
  margin-top: 22px;
  padding:0;
  width: 50%;
}

header li {   
  float: right;
}

header li a {   
  display: block;
  color: black;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

header li a:hover {
  background-color: #111;
  color: white;
}

header h1 {   
  float: left;
  text-align: left;
  line-height: 0;
  font-size: 2em;
}

<header>
  <h1><a href="index.html">Father Bart Gage</a></h1>
  <ul>
    <li><a id="about" href="#">ABOUT</a></li>
    <li><a href="<!-- mailto:[email protected] -->">CONTACT</a></li>
  <div class="dropdownwrapper">
    <div class="dropdown">
         <li><div class="dropbtn" onClick=”return true”>SCRIPTURE</div></li>
      <div class="dropdown-content">
          <a id="mark" href="#">Mark</a>
          <a id="matthew" href="#">Matthew</a>
          <a id="luke" href="#">Luke</a>
          <a id="john" href="#">John</a>
      </div> 
    </div>
    </div>
    </ul>
</header>
like image 648
Chris Avatar asked May 13 '16 14:05

Chris


1 Answers

You have to move the dropdown-content element into the list item:

<div class="dropdown">
      <li>
          <div class="dropbtn" onClick=”return true”>SCRIPTURE</div>

          <div class="dropdown-content">
              <a id="mark" href="#">Mark</a>
              <a id="matthew" href="#">Matthew</a>
              <a id="luke" href="#">Luke</a>
              <a id="john" href="#">John</a>
          </div> 
     </li>
</div>
like image 59
Mark Cidade Avatar answered Oct 10 '22 03:10

Mark Cidade