Issue with collapsing custom-height navigation bar in Bootstrap 4

I have implemented a Bootstrap 4 navbar with a brand logo image sized at 150px x 33px.

Now, I want to increase the height of the navbar to 80px. To do this, I added min-height: 80px; in my CSS.


<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <title>Title</title>
  <link href="../system/bootstrap/dist/css/bootstrap.css" rel="stylesheet">

  <style>
    .navbar {
      min-height: 80px;
      background-color: #FFFFFF;
      border-bottom-color: #D8D8DD;
      border-bottom-style: solid;
      border-bottom-width: 1px;
    }
  </style>
</head>

<body>
  <nav class="navbar navbar-expand-lg fixed-top navbar-light">

    <a class="navbar-brand" href="#"><img src="logo-placeholder-150px-33px.png" ></a>

    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navigation01">
      <span class="navbar-toggler-icon"></span>
    </button>

    <div class="collapse navbar-collapse" id="navigation01">
      <ul class="navbar-nav">
        <li class="nav-item"><a class="nav-link active " href="#">Item 1</a></li>
        <li class="nav-item"><a class="nav-link" href="#">Item 2</a></li>
        <li class="nav-item"><a class="nav-link" href="#">Item 3</a></li>
      </ul>
    </div>
  </nav>

<script src="../system/jquery/dist/jquery.js"></script>
<script src="../system/popper.js/dist/popper.js"></script>
<script src="../system/bootstrap/dist/js/bootstrap.js"></script>

</body>
</html>

When viewed on smaller screens, the menu collapses correctly and the hamburger icon is displayed.

However, when I click on the hamburger icon to open the menu, the position of the logo and the icon shift slightly towards the top.

https://i.stack.imgur.com/eQyNi.png

How can I resolve this issue?

Answer №1

Instead of using min-height, try utilizing padding to adjust the height of your navbar. By increasing the padding in the navbar class, you can resolve this issue.

.navbar {
    padding: .6rem 1rem;
    background-color: #FFFFFF;
    border-bottom-color: #D8D8DD;
    border-bottom-style: solid;
    border-bottom-width: 1px;
}

Answer №2

To achieve the desired min-height of 80px for navbar-brand, it is recommended to adjust the min-height property and remove the padding (py-0) from the navbar element...

<nav class="navbar navbar-expand-lg fixed-top navbar-light py-0">
    <a class="navbar-brand align-items-center d-flex" href="#"><img src="//placehold.it/150x33"></a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navigation01">
        <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navigation01">
        <ul class="navbar-nav">
            <li class="nav-item"><a class="nav-link active " href="#">Item 1</a></li>
            <li class="nav-item"><a class="nav-link" href="#">Item 2</a></li>
            <li class="nav-item"><a class="nav-link" href="#">Item 3</a></li>
        </ul>
    </div>
</nav>

View the Demo

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

Scraping Websites with SimpleHTMLDom in PHP

I am struggling to extract specific data from a table on a website page, particularly the columns name, level, and experience. The table's alternating row colors (zebra pattern) are complicating this task. I have implemented SimpleHTMLDom for this pu ...

Utilizing URL parameters to send data to a Python CGI script

My goal is to pass parameters into my cgi script in order to display a specific post when a URL like www.helloworld.com/cgi-bin/world.py?post=101 is entered. I've attempted the following: link = '<a href="world.py?post=%s">test</a>& ...

Creating a Timeless Banner with the Magic of `background:url()`

I have a banner placed within a div tag that displays my banner image. I am trying to create a fading effect when transitioning to the next image, but I am struggling to achieve this. I attempted to use jQuery fadeIn(), however, it did not work as expected ...

Encountering a NullPointerException when transferring inputs from scala.html to Controller as a form in Play framework (version 2.8.*) using

I am currently developing a Java web application using the Play Framework (2.8.19). In the process of creating a registration page, I encountered an issue with passing inputs from the registration page written in Scala to the controller class that is respo ...

The code is triggering IE 8 to switch to compatibility mode resembling IE7

I have created a custom javascript function that generates a pop-up, and I am invoking this function in my code. However, every time I click the button, the browser switches to IE 7 compatibility mode and the pop-up appears behind the button. Below is my ...

What is the best way to use jQuery to update the color of an SVG shape?

Hello everyone! I'm excited to be a part of this community and looking forward to contributing in the future. But first, I could really use some assistance with what seems like a simple task! My focus has always been on web design, particularly HTML ...

What is the most effective approach to seamlessly conceal and reveal a button with the assistance

I have two buttons, one for play and one for pause. <td> <?php if($service['ue_status'] == "RUNNING"){ $hideMe = 'd-none'; } ?> <a href="#" class="btn btn-warning ...

A helpful tip for those working with jQuery or WordPress PHP: Use a script that calculates the number of characters in a text, identifies the last space, and replaces everything after

Is there a way to restrict the amount of text shown within a div sourced from a WordPress Custom Field? <?php $textcount = strlen(get_field('custom_quote')); ?> <?php if ( $textcount > 250 ) : ?> <?php the_field('custom ...

Unable to align text in the middle of the header

Seeking help with my design flaws, I have created a fiddle to showcase the issues that arise when attempting to make it responsive. The main problem is that the HEADING IN CENTER text is not aligned properly in the center. If I remove the position attribut ...

Trouble with saving the positioning after drag and drop

I am currently facing an issue with my drag-and-drop script where the coordinates of positioned relative divs are not being saved in the same position when I reload. These divs are contained within a container with specific height and width, restricting t ...

The reason the CSS direct descendant selector does not affect Angular components

We are working with a basic main.html. <app> <sidebar></sidebar> <main-content> <router-outlet></router-outlet> </main-content> </app> After loading a component through routing (changing the ...

Update the appearance of a cell if the value within it is equal to zero

I have discovered a way to achieve this using inputs. input[value="0"] { background-color:#F7ECEC; color:#f00;} Now, I am looking for assistance in applying the same concept to table cells. Can anyone provide guidance? Thank you. ...

Unable to trigger JQuery .blur event

I am currently working on implementing server-side validation for an input field that needs to be validated when it loses focus. However, I'm running into an issue where the alert is not triggered when the input field loses focus. Here's a snipp ...

Strategies for styling the contents within <details> while excluding <summary> in CSS

I'm attempting to apply a 10px padding to the Story box using CSS, without introducing any additional HTML elements into the website code. Is there a way to include the padding in the Story box without incorporating a new HTML element? To clarify: H ...

As soon as I hit the submit button on my website form, the URL is automatically refreshed with the information I provided

I am a beginner when it comes to forms and recently copied and pasted this login snippet code: <div class="login-form-1"> <form id="login-form" class="text-left"> <div class="main-login-form"> <div class="login-group"> ...

Emphasize the current page's menu item for the user viewing it

I'm looking for a way to visually emphasize the current menu item so that users can easily identify the page they are currently on. This could be achieved through bolding or underlining, whichever works best. I'm hoping to accomplish this using o ...

Both the maxlenght and ng-maxlength directives appear to be ineffective in AngularJS

In my HTML file, I have the following input: <input name="password" id="newPasswordConfirmation" ng-model="newPasswordConfirmation" type="number" inputmode="numeric" placeholder="" required ...

What could be causing my CSS relative positioning to malfunction?

I am struggling to adjust the positioning of my divs using relative and absolute properties. Any advice on how to resolve this issue would be greatly appreciated. Thank you. Example Code: <div id="game"><img src="gta-game.jpg" height="100" width ...

Chrome's behavior of reducing the width of inline elements when the content is dynamic

Upon opening the specified URL in Google Chrome, an issue can be observed where on the initial load everything appears fine. However, upon refreshing, the width of the three items at the top (Bedingungen, Preise, and So geht's) collapse. This seems to ...

What is the best way to use createElement in JavaScript to insert <p> and <span> elements within a <div>?

I am currently experimenting with generating sentences accompanied by draggable text boxes. To achieve this, I intend to construct the following HTML structure using JavaScript exclusively: <div> <p>Data1<span class = "smallBox droppabl ...