【问题标题】:how to customize the size of hover in navigation bar?如何自定义导航栏中悬停的大小?
【发布时间】:2017-12-27 21:50:35
【问题描述】:

我正在学习引导程序 我正在尝试创建一个导航栏,当我们向下滚动时它会缩小,并且还希望悬停在我尝试了很多但我无法做到的全尺寸链接上。请帮我制作这个导航栏,在链接上完全悬停。以下是我写的代码:

HTML 代码

<nav class="navbar navbar-default navbar-fixed-top">
  <div class="container-fluid" id="fullheader">
    <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>                        
      </button>
      <a class="navbar-brand" href="#">WebSiteName</a>
    </div>
    <div>
      <div class="collapse navbar-collapse navbar-right" id="myNavbar">
        <ul class="nav navbar-nav">
          <li><a href="#section1">Section 1</a></li>
          <li><a href="#section2">Section 2</a></li>
          <li><a href="#section3">Section 3</a></li>
          <li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Section 4 <span class="caret"></span></a>
            <ul class="dropdown-menu">
              <li><a href="#section41">Section 4-1</a></li>
              <li><a href="#section42">Section 4-2</a></li>
            </ul>
          </li>
        </ul>
      </div>
    </div>
  </div>
</nav>

css代码

.navbar{
  width: 100%;
  padding: 40px 0;
  background-color:#FFf;
    border-bottom: 1px solid #e1e1e1;
  /* animation magic */
  transition: all 0.4s ease-in-out;
  -webkit-transition: all 0.4s ease-in-out;
  -moz-transition: all 0.4s ease-in-out ;
  z-index: 9999;
  top: 0;
  position: fixed;
  }

.navbar-default{
background-color:#fff !important;}

.shrink{
  padding: 10px 0;
}


.navbar-default .navbar-brand{
    font-size: 30px;
    -webkit-transition: all 0.4s ease-out;
    transition: all 0.4s ease-out;
}

.navbar-default .navbar-brand,.navbar-default .navbar-brand:hover{
    color: #646464;
    margin-left: 80px !important;
}

.shrink .navbar-brand{
    font-size: 20px;
}


.navbar-default .navbar-nav>li>a:hover, .navbar-default .navbar-nav>.active>a{
    background-color: #00CCFF!important;
    display:block;
}



.navbar-default .navbar-nav>li>a{
    color: #FF0000 !important;
    font-size: 16px;
    font-weight: 500;
}

js代码

    $(document).ready(function(){
      $('body').scrollspy({target: ".navbar", offset: 50});   
      $("#myNavbar a").on('click', function(event) {
        if (this.hash !== "") {
          event.preventDefault();
          var hash = this.hash;
          $('html, body').animate({
            scrollTop: $(hash).offset().top
          }, 800, function(){
            window.location.hash = hash;
          });
        }  
      });
    });

$(window).scroll(function(){
            $scrol=$(document).scrollTop();
            //console.log($scrol);
            if($scrol > 100){
              $(".navbar").addClass("shrink");
            }
            else
            {
                $(".navbar").removeClass("shrink");
            }
        });

【问题讨论】:

    标签: jquery html css bootstrap-4


    【解决方案1】:

    你的意思是这样吗? codepen.io

    .navbar{
      width: 100%;
      background-color:#FFf;
        border-bottom: 1px solid #e1e1e1;
      /* animation magic */
      transition: all 0.4s ease-in-out;
      -webkit-transition: all 0.4s ease-in-out;
      -moz-transition: all 0.4s ease-in-out ;
      z-index: 9999;
      top: 0;
      position: fixed;
      }
    
    .navbar-default{
    background-color:#fff !important;
    min-height: auto;}
    
    .navbar-default .navbar-nav>li>a {
      margin: 0 10px;
      padding: 40px 0;
        -webkit-transition: all 0.4s ease-in-out;
      -moz-transition: all 0.4s ease-in-out ;
    }
    
    .shrink.navbar-default .navbar-nav>li>a,
    .shrink.navbar-default .navbar-brand {
      padding: 10px 0;
      height: 40px;
    }
    
    
    .navbar-default .navbar-brand{
      padding: 40px 0;
        font-size: 30px;
        -webkit-transition: all 0.4s ease-out;
        transition: all 0.4s ease-out;
      min-height: auto;
    height: auto;
    }
    
    .navbar-default .navbar-brand,.navbar-default .navbar-brand:hover{
        color: #646464;
        margin-left: 80px !important;
    }
    
    .shrink .navbar-brand{
        font-size: 20px;
    }
    
    
    
    .navbar-default .navbar-nav>li>a:hover, .navbar-default .navbar-nav>.active>a{
        background-color: #00CCFF!important;
        display:block;
    }
    
    
    
    .navbar-default .navbar-nav>li>a{
        color: #FF0000 !important;
        font-size: 16px;
        font-weight: 500;
    }
    

    【讨论】:

      【解决方案2】:

      好的,我认为@Nikola Kostov 的回答让滚动正确。这是你想要的悬停全尺寸,像这样的东西吗?

        body {height: 2000px;}
      .navbar{
        width: 100%;
        background-color:#FFf;
          border-bottom: 1px solid #e1e1e1;
        /* animation magic */
        transition: all 0.4s ease-in-out;
        -webkit-transition: all 0.4s ease-in-out;
        -moz-transition: all 0.4s ease-in-out ;
        z-index: 9999;
        top: 0;
        position: fixed;
        }
      
      .navbar-default{
      background-color:#fff !important;
      min-height: auto;}
      
      .navbar-default .navbar-nav>li>a {
        margin: 0 10px;
        padding: 40px 0;
          -webkit-transition: all 0.4s ease-in-out;
        -moz-transition: all 0.4s ease-in-out ;
      }
      
      .shrink.navbar-default .navbar-nav>li>a,
      .shrink.navbar-default .navbar-brand {
        padding: 10px 0;
        height: 40px;
      }
      
      
      .navbar-default .navbar-brand{
        padding: 40px 0;
          font-size: 30px;
          -webkit-transition: all 0.4s ease-out;
          transition: all 0.4s ease-out;
        min-height: auto;
      height: auto;
      }
      
      .navbar-default .navbar-brand,.navbar-default .navbar-brand:hover{
          color: #646464;
          margin-left: 80px !important;
      }
      
      .shrink .navbar-brand{
          font-size: 20px;
      }
      
      
      
      .navbar-default .navbar-nav>li>a:hover, .navbar-default .navbar-nav>.active>a{
          background-color: #00CCFF!important;
          font-size: 30px;
          display:block;
      }
      
      
      
      .navbar-default .navbar-nav>li>a{
          color: #FF0000 !important;
          font-size: 16px;
          font-weight: 500;
      }
      

      【讨论】:

        猜你喜欢
        • 2016-03-08
        • 1970-01-01
        • 2011-07-05
        • 1970-01-01
        • 1970-01-01
        • 2017-09-02
        • 2022-07-18
        • 2019-07-10
        • 1970-01-01
        相关资源
        最近更新 更多