实现css垂直制表符

时间:2016-10-13 17:44:33

标签: jquery html css tabs materialize

我想使用materialize-css tabs来制作如下内容:



<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Tabs - Vertical Tabs functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#tabs" ).tabs().addClass( "ui-tabs-vertical ui-helper-clearfix" );
    $( "#tabs li" ).removeClass( "ui-corner-top" ).addClass( "ui-corner-left" );
  } );
  </script>
  <style>
  .ui-tabs-vertical { width: 55em; }
  .ui-tabs-vertical .ui-tabs-nav { padding: .2em .1em .2em .2em; float: left; width: 12em; }
  .ui-tabs-vertical .ui-tabs-nav li { clear: left; width: 100%; border-bottom-width: 1px !important; border-right-width: 0 !important; margin: 0 -1px .2em 0; }
  .ui-tabs-vertical .ui-tabs-nav li a { display:block; }
  .ui-tabs-vertical .ui-tabs-nav li.ui-tabs-active { padding-bottom: 0; padding-right: .1em; border-right-width: 1px; }
  .ui-tabs-vertical .ui-tabs-panel { padding: 1em; float: right; width: 40em;}
  </style>
</head>
<body>
 
<div id="tabs">
  <ul>
    <li><a href="#tabs-1">Nunc tincidunt</a></li>
    <li><a href="#tabs-2">Proin dolor</a></li>
    <li><a href="#tabs-3">Aenean lacinia</a></li>
  </ul>
  <div id="tabs-1">
    <h2>Content heading 1</h2>
    <p>Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. Donec sollicitudin mi sit amet mauris. Nam elementum quam ullamcorper ante. Etiam aliquet massa et lorem. Mauris dapibus lacus auctor risus. Aenean tempor ullamcorper leo. Vivamus sed magna quis ligula eleifend adipiscing. Duis orci. Aliquam sodales tortor vitae ipsum. Aliquam nulla. Duis aliquam molestie erat. Ut et mauris vel pede varius sollicitudin. Sed ut dolor nec orci tincidunt interdum. Phasellus ipsum. Nunc tristique tempus lectus.</p>
  </div>
  <div id="tabs-2">
    <h2>Content heading 2</h2>
    <p>Morbi tincidunt, dui sit amet facilisis feugiat, odio metus gravida ante, ut pharetra massa metus id nunc. Duis scelerisque molestie turpis. Sed fringilla, massa eget luctus malesuada, metus eros molestie lectus, ut tempus eros massa ut dolor. Aenean aliquet fringilla sem. Suspendisse sed ligula in ligula suscipit aliquam. Praesent in eros vestibulum mi adipiscing adipiscing. Morbi facilisis. Curabitur ornare consequat nunc. Aenean vel metus. Ut posuere viverra nulla. Aliquam erat volutpat. Pellentesque convallis. Maecenas feugiat, tellus pellentesque pretium posuere, felis lorem euismod felis, eu ornare leo nisi vel felis. Mauris consectetur tortor et purus.</p>
  </div>
  <div id="tabs-3">
    <h2>Content heading 3</h2>
    <p>Mauris eleifend est et turpis. Duis id erat. Suspendisse potenti. Aliquam vulputate, pede vel vehicula accumsan, mi neque rutrum erat, eu congue orci lorem eget lorem. Vestibulum non ante. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce sodales. Quisque eu urna vel enim commodo pellentesque. Praesent eu risus hendrerit ligula tempus pretium. Curabitur lorem enim, pretium nec, feugiat nec, luctus a, lacus.</p>
    <p>Duis cursus. Maecenas ligula eros, blandit nec, pharetra at, semper at, magna. Nullam ac lacus. Nulla facilisi. Praesent viverra justo vitae neque. Praesent blandit adipiscing velit. Suspendisse potenti. Donec mattis, pede vel pharetra blandit, magna ligula faucibus eros, id euismod lacus dolor eget odio. Nam scelerisque. Donec non libero sed nulla mattis commodo. Ut sagittis. Donec nisi lectus, feugiat porttitor, tempor ac, tempor vitae, pede. Aenean vehicula velit eu tellus interdum rutrum. Maecenas commodo. Pellentesque nec elit. Fusce in lacus. Vivamus a libero vitae lectus hendrerit hendrerit.</p>
  </div>
</div>
 
 
</body>
</html>
&#13;
&#13;
&#13;

有可能吗?

2 个答案:

答案 0 :(得分:3)

使用此HTML

<div class="container">
  <div class="row">
    <div class="col m4">
      <ul class="tabs">
        <li class="tab"><a href="#test1">Tab 1</a></li>
        <li class="tab"><a class="active" href="#test2">Tab 2</a></li>
        <li class="tab"><a href="#test3">Tab 3</a></li>
        <li class="tab"><a href="#test4">Tab 4</a></li>
        <li class="tab"><a href="#test5">Tab 5</a></li>
        <li class="tab"><a href="#test6">Tab 6</a></li>
      </ul>
    </div>
    <div class="col m8">
      <div id="test1" class="col tab-content">Tab 1</div>
      <div id="test2" class="col tab-content">Tab 2</div>
      <div id="test3" class="col tab-content">Tab 4</div>
      <div id="test4" class="col tab-content">Tab 4</div>
      <div id="test5" class="col tab-content">Tab 4</div>
      <div id="test6" class="col tab-content">Tab 4</div>
    </div>
  </div>
</div>

添加一些CSS

.tabs{
height: auto;
white-space: normal;
}
.tab{
display: block;
width: 100%;
border-bottom: 1px solid #f0f0f0;
}
.tab-content{
height: 200px;
width: 100%;
background: #fcfcfc;
border:1px solid #f0f0f0;
}
.indicator{
display: none;
}

&#13;
&#13;
.tabs {
  height: auto;
  white-space: normal;
}

.tab {
  display: block;
  width: 100%;
  border-bottom: 1px solid #f0f0f0;
}

.tab-content {
  height: 200px;
  width: 100%;
  background: #fcfcfc;
  border: 1px solid #f0f0f0;
}

.indicator {
  display: none;
}
&#13;
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css" rel="stylesheet" />
<div class="container">
  <div class="row">
    <div class="col m4">
      <ul class="tabs">
        <li class="tab"><a href="#test1">Tab 1</a></li>
        <li class="tab"><a class="active" href="#test2">Tab 2</a></li>
        <li class="tab"><a href="#test3">Tab 3</a></li>
        <li class="tab"><a href="#test4">Tab 4</a></li>
        <li class="tab"><a href="#test5">Tab 5</a></li>
        <li class="tab"><a href="#test6">Tab 6</a></li>
      </ul>
    </div>
    <div class="col m8">
      <div id="test1" class="col tab-content">Tab 1</div>
      <div id="test2" class="col tab-content">Tab 2</div>
      <div id="test3" class="col tab-content">Tab 4</div>
      <div id="test4" class="col tab-content">Tab 4</div>
      <div id="test5" class="col tab-content">Tab 4</div>
      <div id="test6" class="col tab-content">Tab 4</div>
    </div>
  </div>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

我只是创建了一个新的简单版本

materialized css vertial tab on codepen

full page layout css, working, sample on codepen

我用materialize.1.0.0 / css / materialize.min.css测试了

您必须通过在页面中添加样式标签来覆盖默认的水平制表符CSS,

页面下方的样式标签将覆盖默认标签,并将其转换为垂直标签

<style>
  .tabs-vertical .tabs {
   height: auto;
   -ms-flex-direction: column;
   -webkit-flex-direction: column;
   flex-direction: column;
    display: -webkit-flex;
   display: flex;
   }
   
   .tabs-vertical .tab {
                  width: 100%;
                }
                .tabs-vertical .tab .active {
                  -moz-transition: border-color .5s ease;
                  -o-transition: border-color .5s ease;
                  -webkit-transition: border-color .5s ease;
                  transition: border-color .5s ease;
                  border-right: 3px solid #424242;
                }
                .tabs-vertical .tab :hover {
                  border-right: 3px solid #eeeeee;
                }
                .tabs-vertical .indicator {
                  display: none;
                }
                .tabs-vertical .tab-content {
                  display: none;
                }
                .tabs-vertical > .tab-content .active {
                  display: block;
                }

        </style>



<script src="../../../../share/lib/jquery/dist/jquery.min.js"></script>
<link rel="stylesheet" href="../../../../share/lib/materialize.1.0.0/css/materialize.min.css">
<script src="../../../../share/lib/materialize.1.0.0/js/materialize.min.js"></script>

   

original working: codepen