Guide to creating a navigation bar that expands when you expand navigation items

My portfolio website features a handful of navigation items for various views. I simply copied the default navigation code from the Bootstrap site. However, when I expand the "hamburger" menu, the navigation remains the same size, causing the expanded items to overlap with the border of my navigation bar. Here's an illustration:

https://i.sstatic.net/aFXCv.png

I've searched the Bootstrap site for solutions to this issue, but haven't found anything relevant. Could it be related to the presence of the border in my navigation bar? Below is the code snippet for my navigation bar:

.navbar{
    height: 10.0rem;
    border-bottom: 1px solid rgb(168, 168, 168);
}
.bg-light {
    background-color: white !important;
}
.navbar-collapse{
    padding-left: 0;
}

#options{
    list-style-position: inside;
    padding-left: 12rem;
}
#options li{
    padding-left: 1rem;
    padding-right: 1rem;
    font-size: 1.2rem;
    font-family: Raleway;
}
li a:hover{
    border-bottom: 0.001rem solid black;
}
.navbar-brand{
    font-size: 4rem;
    padding-left: 3rem;
    font-family: Raleway;
    font-weight: 400;
}
#header-container {
    display: flex;
    flex-direction: row-reverse;
    justify-content: right;
    width: 50%;
    height: 50%;
    margin: 0 0 0 10%;
    padding-left: 30%;
}

html{
    height: fit-content;
}
body {
    padding-top: 5.0rem;
  }
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Alan Alban - Portfolio</title>
</head>
  <body>
  <nav class="navbar navbar-expand-lg navbar-light bg-light">
    <a class="navbar-brand" href="#">Alan Alban</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <section id="header-container">
      <div class="collapse navbar-collapse" id="navbarNav">
        <ul class="navbar-nav" id="options">
          <li class="nav-item active">
            <a class="nav-link" href="/">Experience <span class="sr-only">(current)</span></a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="/projects">Projects</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="/skills">Skills</a>
          </li>
        </ul>
      </div>
    </section>
  </nav>
  
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</body>
</html>

Your assistance is greatly appreciated.

Answer №1

Don't forget to include bootstrap.min.js along with jquery.min.js in your imports.

<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f4849b84849186da9e87b4c5dac5c2dac5">[email protected]</a>/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="01636e6e75727573607141352f342f32">[email protected]</a>/dist/js/bootstrap.min.js" integrity="sha384-w1Q4orYjBQndcko6MimVbzY0tgp4pWB4lZ7lr30WKz0vr/aWKhXdBNmNb5D92v7s" crossorigin="anonymous"></script>

This script should be added at the end of your body section, just before the closing tag.

Also, remember to place your CSS in the head section of your HTML document.

For more guidance, refer to the official documentation provided below:

https://getbootstrap.com/docs/4.5/getting-started/introduction/

You'll find useful examples there to kickstart your project effectively.

Answer №2

I finally identified the root of the issue.

.navbar{
    height: 10.0rem;
    border-bottom: 1px solid rgb(168, 168, 168);
}

The code snippet above depicts my initial attempt to adjust the width of the navbar. By removing the height property, I was able to resolve the problem successfully.

https://i.sstatic.net/CKAza.png

My assumption is that by specifying a height, I was essentially restricting the navigation bar to a specific size. I am considering trying a minimum height value to see if that yields the desired outcome. However, the current setup looks satisfactory with the padding applied to the navigation elements.

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

Uncovering the secrets of extracting form parameters with jquery.ajax in asp.net

In search of a method to extract form parameters in C# similar to Java's request.getParameter("blah"). I am currently serializing my form with jQuery and sending it to a web method, but I need assistance in extracting the data. Using ajax. $("#btn" ...

Unlocking the potential of the :not selector when combined with the :nth-of-type selector

My current project involves styling a table. I am looking to apply a specific background color to each odd row, excluding the first row which contains headers. I attempted the following code without success: .new-items-table tr:nth-of-type(odd):not(.new- ...

Prevent divs from jumping to a new line with the float property

I've been busy working on a responsive webpage and so far, everything is going smoothly. The only issue I'm facing is that when the browser window size decreases and reaches a certain point, the div elements jump to the next line. Take a look at ...

Issue with localStorage failing to save comments added at the beginning

Here is a link to the fiddle I am working on. My goal is to store prepended comments in a ul by saving the ul as a variable, and use localStorage to save it in the browser. The HTML structure of the project: <h1>Commentia!!!</h1> <textarea ...

Leveraging JavaScript's Document.write() function to generate an HTML hyperlink

I am struggling with a URL stored in a variable (var URL). My initial attempt was this: document.write("<a href='"+url+"'>LINK</a>"); Unfortunately, it is not working as expected. Any suggestions on how to fix this? This is the ex ...

Creating dynamic forms with JQuery and ReactJS

I have been tasked with creating a form-builder that will be integrated into an application. My role is to focus on designing the front-end using ReactJS. The client’s requirements are very similar to the features of the "jQuery Form-Builder," so I decid ...

Organizing the Outcomes of an Array

After a successful ajax request, I receive an array that contains information about various locations. Here is how the array looks: List of Locations: [{ "locationID": "9", "locationName": "Employee Residenc ...

Expandable fluid inline svg that dynamically fills the remaining space alongside text within a flex row

How can I ensure that an inline SVG occupies all available space within a row without specifying its height across different screen sizes? The solution involves setting the SVG to have 100% height with a viewBox, allowing it to adjust accordingly while ma ...

Safari fails to refresh CSS when it comes to dynamic attributes

Take a look at this simple demonstration: http://jsfiddle.net/fE8ry/ I am attempting to modify the attribute of a div, and based on the attribute's value, apply the corresponding CSS. When the page loads, the attribute selector functions correctly a ...

Using CSS to align the position of a div with the last word position of an h4 element

Trying to figure out how to position a div at the end of an h4 text element has been challenging. When the h4 text is on a single line, it's easy to place the div correctly. However, things get complicated when the text spans multiple lines. In that c ...

Utilize HTML styling for enhancing the detail view in ASP.NET MVC

Currently, I am working on a detailed view page that looks like the following: https://i.sstatic.net/Kw9aE.jpg My objective is to display relevant fields with HTML effects, if applicable. Below is a snippet of the CSHTML code for the aforementioned view ...

Unable to locate the element within the specified div using xpath or css selector

I have attempted to retrieve the output "January 27" using this code: task_offer_deadline = driver.find_element_by_xpath('//*[@id="table"]/div[2]/div/a/div[1]/span[2]/div/em').text The xpath was obtained from Google Chrome Console. Here is a sn ...

Is there a way to track and detect alterations to an element using JavaScript or jQuery

Can I detect the addition of a specific CSS class to an element without having to create a new event? ...

Require a split dropdown feature that does not rely on bootstrap

After searching extensively for a split button dropdown field without relying on any bootstrap package, I came up empty-handed. It seems like such a specific feature is hard to find without external dependencies. https://i.sstatic.net/stoMz.png ...

Stop the bubbling effect of :hover

How can the hover effect be prevented for the parent element when hovering over its children? Please take a look at the following code snippet: const parent = document.getElementById('parent') parent.onmouseover = function testAlert(e) { /* ...

Ways to apply CSS to a changing div ID

I am looking to apply CSS to a dynamically generated div ID. var status = var status = item.down().next().innerHtml(); if(status == "test") { var c = 'item_'+i ; c.style.backgroundColor = 'rgb(255, 125, 115)'; //'ite ...

Implement a scrolling feature to the tooltip when using "data-toggle"

I'm struggling with a piece of code that showcases a tooltip when the user hovers over the question circle icon. The tooltip's content can't exceed 1000 characters, but I need to figure out how to make the overflow scroll by adjusting the to ...

Exploring the potential of Python loops within Selenium capabilities

My latest project involves scraping data from a search page. Specifically, I need to extract the title, price, and link for each of the 25 results on the page. To achieve this, I'm working with Xpath and utilizing an incremental div number associated ...

When I click the search button on my website, it automatically scrolls to a particular <img> or <a> tag

My objective is to have the page automatically scroll down to a specific image when I perform a search using the search bar. Here is the HTML code for the search bar and button: <form id="search-form" href="#test1" class="smoothscroll"> <inpu ...

Remove a row from a table using the hyperlink reference

I am facing an issue where I want to delete a row in the table along with the corresponding database entry by clicking on a href link, but it doesn't work as expected: <table cellpadding="0" cellspacing="0" border="0" class="display" id="example"& ...