【问题标题】:How do I make CSS tab ui into a nav bar如何将 CSS 选项卡 ui 变成导航栏
【发布时间】:2019-06-05 14:18:04
【问题描述】:

我正在尝试将以下选项卡设置为固定在底部的引导导航。但是,它保持在顶部,我如何使用我拥有的内容创建导航栏。谢谢你。 Here 是错误的页面。选项卡“一个”有自己的 ul 但不显示。 Tab One 应该显示“page 1”和“page 2”。

html 正文:

$(document).ready(function() {
  $("#content").find("[id^='tab']").hide(); // Hide all content
  $("#tabs li:first").attr("id","current"); // Activate the first tab
  $("#content #tab1").fadeIn(); // Show first tab's content

  $('#tabs a').click(function(e) {
      e.preventDefault();
      if ($(this).closest("li").attr("id") == "current"){ //detection for current tab
       return;       
      }
      else{             
        $("#content").find("[id^='tab']").hide(); // Hide all content
        $("#tabs li").attr("id",""); //Reset id's
        $(this).parent().attr("id","current"); // Activate this
        $('#' + $(this).attr('name')).fadeIn(); // Show content for the current tab
      }
  });
});
#tabs {
  overflow: hidden;
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}

#tabs li {
  float: left;
  margin: 0 .5em 0 0;
}

#tabs a {
  position: relative;
  background: #ddd;
  background-image: linear-gradient(to bottom, #fff, #ddd);  
  padding: .7em 3.5em;
  float: left;
  text-decoration: none;
  color: #444;
  text-shadow: 0 1px 0 rgba(255,255,255,.8);
  border-radius: 5px 0 0 0;
  box-shadow: 0 2px 2px rgba(0,0,0,.4);
}

#tabs a:hover,
#tabs a:hover::after,
#tabs a:focus,
#tabs a:focus::after {
  background: #fff;
}

#tabs a:focus {
  outline: 0;
}

#tabs a::after {
  content:'';
  position:absolute;
  z-index: 1;
  top: 0;
  right: -.5em;  
  bottom: 0;
  width: 1em;
  background: #ddd;
  background-image: linear-gradient(to bottom, #fff, #ddd);  
  box-shadow: 2px 2px 2px rgba(0,0,0,.4);
  transform: skew(10deg);
  border-radius: 0 5px 0 0;  
}

#tabs #current a,
#tabs #current a::after {
  background: #fff;
  z-index: 3;
}

#content {
  background: #fff;
  padding: 2em;
  height: 220px;
  position: relative;
  z-index: 2; 
  border-radius: 0 5px 5px 5px;
  box-shadow: 0 -2px 3px -2px rgba(0, 0, 0, .5);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<nav class="navbar navbar-inverse fixed-bottom">

<nav>
  <div>
    <ul class="nav navbar-nav" id="tabs">
        <li class="active"><a href="#">Home</a></li>
        <li class="dropdown"><a href="#" name="tab1">One</a>
            <ul class="dropdown-menu">
                <li><a href="#">page 1</a></li>
                <li><a href="#">page 2</a></li>
            </ul>
        </li>
        <li><a href="#" name="tab2">Two</a></li>
        <li><a href="#" name="tab3">Three</a></li>
        <li><a href="#" name="tab4">Four</a></li>

    </ul>
  </div>
</nav>

【问题讨论】:

    标签: javascript html css twitter-bootstrap


    【解决方案1】:

    使用上面的代码很难理解,但你可以试试position: absolute;bottom: 0;

    例子:

    #tabs {
      overflow: hidden;
      width: 100%;
      margin: 0;
      padding: 0;
      list-style: none;
      position: absolute;
      bottom: 0;
    }
    

    或者改变导航栏本身的位置:

    .navbar {
        position: absolute;
        bottom: 0;
        width: 100%;
    }
    

    【讨论】:

      【解决方案2】:

      将您的 .navbar css 更改为 display:fixedbottom:0 并删除边距:底部

      【讨论】:

        猜你喜欢
        • 2019-08-14
        • 1970-01-01
        • 2018-12-21
        • 2017-12-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多