CSS

【CSS】CSSで作成されたドロップダウンメニューPure CSS Dropdown

January 31, 2018
pure-css-dropdown

Pure CSS DropdownはCSSで作成されたドロップダウンメニュー。

HTML

    <nav class="navDefault">
      <div class="dropdown">
         <button>Dropdown</button>
          <ul class="dropdownMenu">
            <li class="dropdownItem"><a href="#" class="dropdownLink">Link</a></li>
            <li class="dropdownItem"><a href="#" class="dropdownLink">Link</a></li>
            <li class="dropdownItem"><a href="#" class="dropdownLink">Link</a></li>
            <li class="dropdownItem"><a href="#" class="dropdownLink">Link</a></li>
          </ul>
      </div>
          
        
    </nav>

CSS

.navDefault {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background-color: #4a4a4f;
}

button {
    border: none;
    
    background-color: #0997d3;
    width: 150px;
    height: 50px;
    color: #fff;
    text-transform: uppercase;
    cursor: pointer;
}
.dropdownMenu {
    list-style: none;
    margin: 0;
    padding: 0;
    z-index:-1;
    position: absolute;
    left: 0;
    right: 0;
    top: 50px;
    width: 150px;
    text-align: center;
    
    box-shadow: 0px 6px 10px 0px rgba(0,0,0,0.2);
    transform: translateY(-100%);
    transition: transform .5s ease-in-out;
    
}

.dropdownLink {
    text-decoration: none;
    
    display: block;
    background-color: #f9f9f9;
    color:#4a4a4f;
    padding: 10px 5px;
    transition: background-color .5s ease-in-out, color .5s ease-in-out;
}

.dropdownLink:hover {
    color: #fff;
    background-color: #a0a0a3;
}
.dropdown {
    width: 150px;
    position: relative;
}

.dropdown:hover button {
    background-color: #018ec5;
}

.dropdown:hover .dropdownMenu {
    transform: translateY(0%);
}