菜单栏在重新调整窗口大小时会被切断

时间:2016-05-15 12:59:21

标签: html css responsive-design

我正在尝试对html页面进行编码,以便在重新调整大小时切换我的菜单。我想在此页面编写菜单,如菜单http://www.templatemonster.com/demo/58695.html任何帮助?

1 个答案:

答案 0 :(得分:0)

我在网站上创建了类似菜单的菜单,

HTML:

<div class="menu">
  <i class='theIcon'></i>
  <ul>
    <li> <a href="#"> Home </a> </li>
    <li> <a href="#"> About </a> </li>
    <li> <a href="#"> Services </a> </li>
    <li> <a href="#"> Blog </a> </li>
    <li> <a href="#"> Gallery </a> </li>
    <li> <a href="#"> Contacts </a> </li>
  </ul>
</div>

式:

.menu{
  text-align:center;
  overflow:hidden;
}
.menu .theIcon{
  display: inline-block;
  width: 20px;
  height: 8px;
  position: relative;
  cursor: pointer;
  border-top: 2px solid #000;
  border-bottom: 2px solid #000;
}
.menu .theIcon:before{
  content: '';
  width: 100%;
  height: 2px;
  background: black;
  position: absolute;
  top: 3px;
  left: 0;
}
.menu ul{
  float:right;
  margin:0;
  padding:0;
  display:none;
  position: absolute;
  top: 40px;
  right: 5%;
  left: 5%;
  background: #CFD8DC;
  text-align:left;
}
.menu ul li{
  list-style:none;
}
.menu ul li a{
  padding:10px;
  display:block;
}

@media only screen and (min-width: 769px) {
    .menu .theIcon{
      display:none;
    }
    .menu ul{
      position:static;
    width:auto;
      display:block !important;
    background:none;
    }
  .menu ul li{
    float:left;
  }
  .menu ul li a{
    padding:0 10px;
  }
}

和脚本:

$('.menu .theIcon').click(function(){
    $(this).next('ul').fadeToggle(300);
});

在这里演示:https://jsfiddle.net/IA7medd/o89pn61t/