The navigation bar remains fixed and unresponsive to changes in screen size

Having trouble making my nav bar collapse and expand with screen size. The code I'm using isn't working, and I can't pinpoint the issue.

I'd like the nav bar to transition into a menu icon when the screen reaches a tablet-like size. Currently, the nav links behave in an unexpected manner when the screen is resized.

Please view the code snippet below:

*{
    margin: 0;
    padding: 0;
    line-height: 1;    
}

body {   
  margin: 0;
  font-family: sans-serif;
  background: #FFFFFF;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overflow-x: hidden;
}

nav {
    margin: 0 0 0 0;
    font-family: 'Lato', Sans-serif;
    font-size: 100%;
    width: auto;
 }

.navbar { 
margin: 0; 
padding-top: 1.5em; 
    padding-bottom: 1.5em; 
    padding-left: 6em;
    padding-right: 5.06em;

background-color: #000; 
} 


.navbar-brand {
color: #fff; 
background-color: #000; 
    font-size: 22px;
    display: inline; 
}

.navbar ul li {  
display: inline; 
} 
 

.navbar ul li a { 
color: #fff; 
background-color: #000; 
    font-size: 18px;
} 

.nav-link {
    padding-left: 15px;
    padding-right: 15px;
}
<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
    <meta name="HandheldFriendly" content="true">

    <link href="graphic-design.css" type="text/css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Lato:300,400,700,900" rel="stylesheet">
      
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.bundle.min.js" integrity="sha384-feJI7QwhOS+hwpX2zkaeJQjeiwlhOP+SdQDqhgvvo1DsjtiSQByFdThsxO669S2D" crossorigin="anonymous"></script>
    <script type="text/javascript"></script>
      
  </head>

 <body>   
<nav class="navbar navbar-expand-md navbar-inverse navbar-fixed-top">
  <div class="container-fluid">
      <a class="logo"><img src="9haus-logo-white.png" alt="9haus logo" width="63px" height="19px"></a>   
      <a class="navbar-brand" href="graphic-design.html">Graphic design</a>
  <div class="navs">
    <ul class="navbar-brand">
      <li class="active"><a class="nav-link" href="graphic-design.html">Work</a></li>
      <li><a class="nav-link" href="graphic-studio.html">Studio</a></li>
      <li><a class="nav-link" href="#">Services</a></li>
    </ul> 
    </div>  
</div>      
</nav>     
    
</body>

</html>

Answer №1

If your Bootstrap 4 navbar isn't functioning as intended, it may be due to incorrect usage of the navbar components.

To see a properly working version of the Bootstrap 4 navbar, make sure all components are included and positioned correctly. No unnecessary CSS or JavaScript hacks are needed:

<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://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

<nav class="navbar navbar-expand-md navbar-light bg-light">
    <a class="navbar-brand" href="graphic-design.html">
        <img src="https://placehold.it/60" width="30" height="30" class="d-inline-block align-top" alt="">
        Graphic design
    </a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>

    <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <ul class="navbar-nav mr-auto">
            <li class="nav-item active">
                <a class="nav-link" href="#">Work <span class="sr-only">(current)</span></a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Studio</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Services</a>
            </li>
        </ul>
    </div>
</nav>

Avoid using custom CSS hacks with Bootstrap 4, as they can create additional problems that require more fixes. Most custom CSS is unnecessary since Bootstrap 4 provides built-in classes for styling including padding and margins.

For reference on Bootstrap 4 spacing utilities, visit:

https://getbootstrap.com/docs/4.0/utilities/spacing/

Keep in mind that the Bootstrap spacing classes, like other Bootstrap classes, are responsive and can be adjusted for different breakpoints as needed.

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

Using AngularJS to showcase information received from socket.io

I'm having an issue with displaying data on a graph using AngularJS after receiving it from socket.io. Even though I can see that the data is being retrieved correctly from the server, when I try to display it on the graph, I only get a message saying ...

The tab content doesn't consume the entire space

Utilizing bootstrap 4 with a left menu feature. Upon clicking an element, a tab is displayed. An ajax call is made to retrieve the thymeleaf fragment. The issue arises where the tab content does not occupy the entire space available. <div class="cont ...

The issue of webkit animation rotation malfunctioning on Nexus Mobile devices

I'm currently working on developing a double ring radar animation within an Ionic hybrid application. The animation functions perfectly when viewed in a web browser, however, I've encountered issues when attempting to run it on the Nexus mobile ...

Is there a way to adjust paragraph sizes in CSS flexbox so they scale with the font size?

After spending hours trying to figure this out on my own, I finally caved and registered on StackOverflow. Despite Google providing plenty of related questions and examples, I still can't find a solution to my specific problem. The issue at hand is c ...

Utilizing the dynamic nth-child selection feature in CSS

There is an element in this code snippet: <div> <li> item 1 </li> <li> item 2 </li> <li> item 3 </li> <li> item 4 </li> </div> I always want to display the first two items, so I used the followi ...

Carousel position images off-center to the right on smaller screens

I created a fullscreen slider using the carousel bootstrap feature. However, when the screen size shrinks, the background image resizes and centers itself. Instead of centering the image on smaller screens, I want it to focus on the right side. Here is ho ...

Ensure that the radio button and its corresponding label are aligned on the same horizontal line

When dealing with multiple radio buttons, each paired with a label, how can you ensure that the button and label always stay on the same line, while also automatically shifting to the next line for the next pair? For example, on a large screen: () Label ...

Guide to positioning Bootstrap 5 toast messages at the center of an ASP.NET Web Form

I have integrated a Bootstrap toast element within an ASP.NET web form as shown below: <asp:Content ID="ctMain" ContentPlaceHolderID="cpMain" runat="server"> <div aria-live="polite" aria-atomic="tru ...

Looking to include some extra padding when an item is displayed - jQuery

So, I'm working on a jQuery code snippet that controls the visibility of a rectangle element: $("#rectangle").hide(); $("#toggle-rec").click(function () { $("#rectangle").toggle(2000); }); This code hides the rectangle initially and toggles it ...

Utilize a jQuery button to horizontally align text with ellipsis

I am currently struggling to align some text with ellipsis horizontally alongside a jquery button and I cannot seem to determine the reason for this issue. You can view my problem on jsfiddle: http://jsfiddle.net/5bVDu/ <span> <span id=&apo ...

Concealing the TinyNav Drop-Down Menu

Currently, I am utilizing TinyNav on my website and it is working wonderfully. However, due to our extensive menu system, the tinynav dropdown appears quite large. I have been attempting to figure out a way to hide all sub-menus without success. I experim ...

Error in zone: 140 - Property 'remove' is not readable

I'm brand new to kendo ui. I successfully set up a prototype in my fiddle with a working delete confirmation window. However, when I try to integrate it into my existing codebase, I encounter an error: Cannot read property 'remove' at the li ...

What steps can I take to ensure my CSS component remains unaffected by the global CSS styles?

My navbar component is not displaying the styles correctly as intended. I have a Navbar.module.css file to style it, but after using next-auth for social login, only the buttons remain unstyled while everything else gets styled. The code snippet for impor ...

Tips for adding a Bootstrap favicon to your Ruby on Rails application

Currently, I am in the process of creating a Rails application and I am facing a challenge in setting a favicon using Bootstrap and font_awesome5_rails gems with the help of 'fa_icon()'. While I have successfully displayed an icon using this meth ...

Restoring styles back to the default CSS settings

I am currently working on creating visualizations using D3, and one challenge that I have encountered is the need to define a lot of styles within my code instead of in my CSS where I would prefer them to be. This necessity arises mainly to support transi ...

In a grid container, a child element utilizing `overflow-y: auto` will not be able to scroll

<script src="https://cdn.tailwindcss.com"></script> <div class="h-screen grid grid-rows-[auto,1fr]"> <div class="bg-slate-300 h-24 flex items-center px-4"> <h1 class="text-3xl">Navbar</h1> </div> <div ...

Problem with Submitting Form using Search Bar

I've tried everything, but I can't seem to get this search form to submit. <div id="search_bar_container" style="z-index:99999"> <div class="container"> <form action="tour-list-search-results.php" method="post" name="searc ...

Is there a way to create a dropdown menu that transforms into a burger icon on smaller screens, while still housing all of my navigation items within it?

I'm currently working on a segment of my header that includes a navbar with 3 links, as well as a dropdown menu listing additional functionalities. Here is the current code I have: <div class="col-md-4 pt-4"> <nav class="navbar ...

The Bootstrap 4 modal quietly disappears without revealing its content

I have encountered an issue with two modals in my navbar. The settings modal is functioning normally, but the other one triggered by the "+" symbol (#quick-add-task-modal) only fades the screen without displaying properly. Despite reviewing the code mult ...

Tips for retrieving the chosen value from a dropdown list in HTML

I'm having an issue with exporting specific values from multiple HTML tables into an excel file. My goal is to only export the selected values from each table, with each table being on a separate tab in the excel file. Currently, when I export the ta ...