简体   繁体   English

如何将垂直菜单转换为手风琴菜单

[英]How to convert an vertical menu to an accordion menu

I'm trying to build a responsive tab menu but I'm trying to go for a accordion like menu (eg the content between the tabs ) when the menu go into the vertical view, but I have no idea how to go about it without losing the responsiveness. 我正在尝试构建一个响应式选项卡菜单,但是当菜单进入垂直视图时,我想尝试一种类似菜单的手风琴(例如,选项卡之间的内容),但是我不知道如何在没有它的情况下进行操作失去响应能力。

HTML 的HTML

<h1>Responsive Tabs</h1>

<div class="tabBox">
<ul class="tabs">
<li><a href="#tab1">Test1</a></li>
<li><a href="#tab2">Test2</a></li>
<li><a href="#tab3">Test3</a></li>
</ul>

<div class="tabContainer">
<div id="tab1" class="tabContent">
  Test1
</div>

<div id="tab2" class="tabContent">
  Test2
</div>

<div id="tab3" class="tabContent">
 Test3
</div>    

CSS 的CSS

    body {
font-family: Arial, sans-serif;
}



 div.tabBox {
width:99.9%;
float:left;
overflow: visible;

} }

 div.tabBox h3 {
  padding:20px 0px;
 }


  ul.tabs {
  margin: 0;
 padding: 0;
 float: left;
 list-style: none;
 height: 32px; 
  width:99.9%;
 }

 ul.tabs li {
 float: left;
 margin: 0;
padding: 0;
height: 32px; 
line-height: 32px; 
margin-bottom: -1px; 
overflow: hidden;
position: relative;
 }

 ul.tabs li a {
 display: block;
 padding: 0 5px;
 outline: none;
 background:none;
 }


  .tabContainer {  
   border-top: none;
   overflow: hidden;
  clear: both;
  float: left;
  width:99.9%;
 min-height:300px;
 margin-bottom:10px;
 }

  .tabContent {
 padding: 20px;
  }

 .tabContent h3 {
 padding:0px;
 }

 /**** TABS STYLES ****/

 div.tabBox h3 {
 }


 ul.tabs {
border-bottom: 1px solid #ccc;
border-left: 1px solid #ccc;
border-top-left-radius:5px;
-moz-border-top-left-radius:5px;
-webkit-border-top-left-radius:5px;
}

 ul.tabs li {

  }

  ul.tabs li a {
 background:#eee;
 text-decoration: none;
 font-size: 11px;
 color: #000;
 outline: none;
 border: 1px solid #ccc;
 border-left: none;
 border-top-left-radius:5px;
 -moz-border-top-left-radius:5px;
 -webkit-border-top-left-radius:5px;
 border-top-right-radius:5px;
 -moz-border-top-right-radius:5px;
 -webkit-border-top-right-radius:5px;
 }

  ul.tabs li a:hover {
  background: #eee;
  }

   ul.tabs li.active {
  border-bottom:1px solid #fff;
  }

  ul.tabs li.active a, ul.tabs li.active a:hover  {  
  background: #fff;
  }

 div.tabContainer {
 border-bottom:1px solid #ccc;
 border-left:1px solid #ccc;
 border-right:1px solid #ccc;
 background:#fff;
  } 

      @media only screen and (max-width: 767px) {

div.tabBox {
    border: 1px solid #ccc;
}

ul.tabs {
height: auto;
display: block;
width:100%;
border-left:0px;
}

ul.tabs li {
    width:100%;
}

ul.tabs li a {
    border-top-left-radius:0px;
    -moz-border-top-left-radius:0px;
    -webkit-border-top-left-radius:0px;
    border-top-right-radius:0px;
    -moz-border-top-right-radius:0px;
    -webkit-border-top-right-radius:0px;    
    border:0px;
}

div.tabContainer {
    border: 0px;
}

 }

here's the fiddle http://jsfiddle.net/Jnewguy/5B5KJ/ 这是小提琴http://jsfiddle.net/Jnewguy/5B5KJ/

Any tips or ideas? 有任何提示或想法吗?

To many different options... it depends how you like to approach this problem. 有许多不同的选择……这取决于您希望如何解决此问题。

1) Add more html for the responsive version. 1)为响应版本添加更多html。

<a href="#tab1">Test1</a>   
<div id="tab1" class="tabContent">
  Test1
</div>
<a href="#tab2">Test2</a>
<div id="tab2" class="tabContent">
  Test2
</div>
<a href="#tab3">Test3</a>
<div id="tab3" class="tabContent">
 Test3
</div>  

Add tab link before each tab and show them only on mobile. 在每个标签前添加标签链接,并仅在移动设备上显示它们。 You hide the default ones and style the new ones with proper js. 您可以隐藏默认的代码,并使用适当的js设置新代码的样式。

2) You can apply the same practice but using JS cloning the tab links and adding each one before the tabs. 2)您可以应用相同的做法,但是使用JS克隆选项卡链接,并在选项卡之前添加每个链接。

$('.tabs li a').each(function(){
    var $self = $(this);
    var href = $self.attr('href');
    var clone = $self.clone();
    $(clone).insertBefore($(href));
})

3) You can append the content inside of the ul>li structure, but you must move it every time you exit/enter the breakpoint 3)您可以将内容附加到ul>li结构内部,但是每次退出/进入断点时必须将其移动

$('.tabContent').each(function(e){
    var $self = $(this);
    $('.tabs li').eq(e).append($self);
})

And some other options, that I can't think of at the moment... 还有一些其他选择,目前我还无法想到...

I don't know why you point him to an accrodion menu questions, since his problem is that he must transform his current vertical to accrodion only in the responsive version... 我不知道你为什么要给他指出一个菜单选项问题,因为他的问题是他只能将他当前的垂直方向转换为仅响应式的菜单...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM