0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

マウスオン(hover)したら下位項目が出てくるメニューの作り方

Last updated at Posted at 2019-08-18

制作物イメージ

スクリーンショット 2019-08-18 22.16.07.png
 <ul class="menu">
   <li class="menu__single">
     <a href="#" class="init-bottom">AAAAAAAAA</a>
   </li>
   <li class="menu__single">
     <a href="#" class="init-bottom">AAAAAAAAA</a>
     <ul class="menu__second-level">
        <li><a href="#">BBBBBB</a></li>
        <li><a href="#">BBBBBB</a></li>
        <li><a href="#">BBBBBB</a></li>
        <li><a href="#">BBBBBB</a></li>
     </ul>
   </li>
   <li class="menu__single">
      <a href="#" class="init-bottom">AAAAAAAAA</a>
   </li>
   <li class="menu__single">
      <a href="#" class="init-bottom">AAAAAAAAA</a>
   </li>
   <li class="menu__single">
      <a href="#" class="init-bottom">AAAAAAAAA</a>
   </li>
 </ul>   
.menu {
    position: relative;
    width: 75%;/* メニュー全体の大きさ */
    text-align: right;
}
.menu > li {
    float: left;
    margin:0 3.6%;/* メニュー間の隙間 */
    letter-spacing: 0.2rem;
}
.menu > li a {
    display: block;
}
ul.menu__second-level {
    visibility: hidden;
    opacity: 0;
    z-index: 1;
    margin:25px 0 0 0;
    padding:10px 2%;
    background:#333333;
}
.menu > li:hover {
    color: #333333;
    -webkit-transition: all .5s;
    transition: all .5s;
}
.menu__second-level li a {
    margin:10px 0 0 0;
    text-align: center;
    font-size:0.8rem;
    color: #ffffff;
}
.menu__second-level li a:hover {
    text-decoration: underline!important;
}
.menu:before,
.menu:after {
    content: " ";
    display: table;
}
.menu:after {
    clear: both;
}
.menu > li.menu__single {
    position: relative;
}
li.menu__single ul.menu__second-level {
    position: absolute;
    width: 150%;/* ここが下位メニューを表示するボックスの大きさ */
    -webkit-transition: all .2s ease;
    transition: all .2s ease;
}
li.menu__single:hover ul.menu__second-level {
    visibility: visible;
    opacity: 1;
}
.menu__second-level:before{
    content: "";
    position: absolute;
    top: -30px;
    left: 50%;
    margin-left: -15px;
    border: 15px solid transparent;
    border-bottom: 15px solid #333333;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?