Tips for adjusting the hover size in a navigation bar

I'm currently learning how to use bootstrap and I'm attempting to create a navbar that shrinks when scrolled down, and I also want the hover effect on the links to be full-height. I've tried multiple approaches but haven't been successful. Can someone please assist me in creating this navigation bar with full-height hover on links? Below is the code I've written:

HTML Code

<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 Code

.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;
}

JavaScript Code

    $(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");
            }
        });

Answer №1

Is this what you're looking for? Check it out here

.nav-bar{
  width: 100%;
  background-color:#FFf;
    border-bottom: 1px solid #e1e1e1;
  /* cool animation */
  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;
  }

.nav-bar-default{
background-color:#fff !important;
min-height: auto;}

.nav-bar-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.nav-bar-default .navbar-nav>li>a,
.shrink.nav-bar-default .navbar-brand {
  padding: 10px 0;
  height: 40px;
}


.nav-bar-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;
}

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

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



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



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

Answer №2

It seems like @Nikola Kostov has nailed the shrink effect on scroll. Is this the desired outcome for enlarging on hover to full size?

  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;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Create a table within the B-Col element that automatically adjusts its size to match the column width using Vue-Bootstrap

Within my Vue component, I have the following code snippet: <b-modal ...> <b-row> <b-col sm="12"> <table > <tr v-for=... :key="key"> <td><strong>{{ key }}: </str ...

Is it possible to create an animation with CSS3 transitions?

Experience a dynamic blinking border animation when hovering over the title: #link_list a:hover { border-left: 10px solid #E3E3E3; animation: blink 1s infinite; -webkit-animation: blink 1s infinite; -moz-animation: blink 1s infinite; -o-animation: blink 1 ...

Create a custom Angular directive that allows you to replace tags while inserting the template

I have created a custom directive that can take templates based on the attribute provided. Check out the Plnkr example JS var app = angular.module('app', []); app.directive('sample', function($compile){ var template1 = '<d ...

Introducing a new left overlay panel popup feature using jQuery Mobile

I'm currently developing a mobile app and I'm having trouble getting a popup to launch on the left overlay panel when clicked on "Sign out". I can't figure out where I'm going wrong. Can someone please provide some suggestions? Thank yo ...

Adjust the height of the outer div automatically

Currently, I am attempting to dynamically set the height of div#container so that it adjusts based on its relative positioning and the absolute positioning of inner divs. Essentially, I want the inner divs to be centered within the container. <div id=" ...

The overflow-x property causes the left side of the component to be cut off when scrolling

When the screen width is insufficient to display a component properly, I need it to be horizontally scrollable. However, when scrolling to the left after making it scrollable due to a smaller screen size, the left side of the component gets cut off and can ...

I am interested in creating some CSS styles to modify the color of a toggle switch's plus sign icon

Can anyone help me customize my Wordpress theme? I'm trying to change the color of my toggle plus signs to white using CSS, but I can't figure it out. Your assistance would be greatly appreciated. Here is the URL: This is the CSS code I attempt ...

Obtain the data of the highlighted row in a telerik grid directly from the client side

I am attempting to retrieve the value of a GridBoundColumn with DataField="id" using JavaScript on the client side. When the user clicks on the image button within a row, I need to extract the id for that specific row and then invoke a web method by passin ...

Is there a way to retrieve the aria-label attribute value from this specific WebElement?

When utilizing Java Selenium, I have access to a WebElement object that corresponds to the following HTML node: <td role="gridcell" class="mat-calendar-body-cell ng-star-inserted" style="width: 25%; padding-top: 7.14286%; paddin ...

Encountering the "node:internal/modules/cjs/loader:1050" error while attempting to execute a folder using the "npm run dev" command

I am encountering an issue while attempting to execute a folder using npm run dev, consistently resulting in the same error message. PS C:\Users\My Name\Desktop\My Folder> npm run dev Debugger attached. > <a href="/cdn-cgi/l/e ...

Organizing table data by columns in a continuous loop

I'm currently working on extracting data from a database, organizing it into tables (potentially multiple tables), and presenting them in columns of 4 across several pages. My main concern is figuring out how to display the tables horizontally like t ...

Trigger an event on an element upon first click, with the condition that the event will only fire again if a different element is clicked

Imagine having 5 span elements, each with an event listener like ` $('.option1').on("click", function(){ option1() }) The event for option 1 is also the default event that occurs on page load. So if no other options are clicked, you won&apo ...

convert text on website using selected option from menu

A dropdown menu allows the user to choose from 3 language options: English, Spanish, and German. The intended functionality is that when a language is selected, the entire content of the site should switch to that language. Unfortunately, this feature is ...

Navigating Bootstrap: Refreshing a full-screen modal with a swipe gesture on mobile devices

I'm currently utilizing Bootstrap 5's full screen modal and I'm exploring how to implement a feature that enables refreshing on mobile devices by swiping down, similar to how you would usually refresh a page. <script src="https://cdn.j ...

Tips on refreshing a div using jQuery while maintaining the functionality of addEventListener

Hi, I am facing an issue with updating the "div" element. The refresh works fine, but after refreshing when I try to click on the updated "div", the addEventListener in my JavaScript code does not seem to work anymore. Can someone please explain why this i ...

How can I prevent clearQueue() from removing future queues?

In my code, I have a button that triggers the showing of a div in 500ms when clicked. After the div is shown, a shake class is added to it after another 500ms. The shake class is then removed after 2 seconds using the delay function. However, if the user c ...

Sliding in a strange way

Are you experiencing a strange behavior with the slider on your website? When you hover over the image, the caption at the bottom slides up and on mouseout it slides down again. It works perfectly on . However, when navigating to portfolio via the menu on ...

Determine the number of rows in the Tabulator's table

Can anyone tell me how to retrieve the number of rows in a table created using Tabulator on a website? Is there a method like table.size or table.length that I can use for this purpose? The table has been initialized with the following code: table = new T ...

Tips for seamlessly playing flowplayer while an mp4 file is loading?

Is there a way for the video to play while it is buffering, rather than waiting for the mp4 to be fully loaded? Thank you. ...

What is the method for choosing a parent element over a child element in CSS?

I am struggling with styling a menu that has a structure like this: <div class="myclass" > <ul> <li> <li> <------- need to style the parent li and not the child li <li> <ul ...