The Bootstrap 4 navigation bar fails to be responsive and remains open despite attempts at styling

Having trouble with my navbar functionality... After applying CSS styling, it loses responsiveness and remains open on smaller screens. Here is the code snippet.

HTML:

<nav class="navbar navbar-expand-sm navbar-dark bg-dark" id="big-bar">
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
            <div class="collapse navbar-collapse" id="navbar-el">
              <div class="navbar-nav">
                <a class="nav-item nav-link active flip" href="home.html">Home <span class="sr-only">(current)</span></a>
                <a class="nav-item nav-link flip" href="mansion.html">Mansion</a>
                <a class="nav-item nav-link flip" href="#third-div">Sacrificial Grounds</a>
                <a class="nav-item nav-link flip" href="#fourth-div">Children of the Forest</a>
                <a class="nav-item nav-link flip" href="#fifth-div">About</a>
              </div>
            </div>
          </nav>

CSS:

body{
  background-color: black;
}

.navbar {
  background: rgba(0, 0, 0, 0) !important;
  margin-top: 50px;
}

#navbar-el {
  display: flex;
  align-items: center;
  justify-content: center;
}

#navbar-el a {
  margin: 0 50px 0 50px;
  font-size: 20px;
  color: white;

}

#navbar-el a:link {
}

#navbar-el a:visited {
}

#navbar-el a:hover {
    color: #ED8105;
}

#navbar-el a:active {
  color: #ED8105 !important;
}

#navbar-el a:focus{
  outline: none;
}

Codepen:https://codepen.io/Sarithan/pen/jvKaGa

Answer №1

To optimize your layout, remove the margin from your anchor tags by setting it to margin: 0 auto;. Additionally, apply justify-content: space-between; to your navbar-nav. I have also included flex-grow: 1; for the navbar-nav.

The following CSS has been added:

.navbar-nav{
  justify-content: space-between;
  flex-grow: 1;
}

Please review the codepen example provided at this link:

https://codepen.io/anon/pen/rZKEvq

Answer №2

The reason it remains open is due to the presence of display:flex in the additional CSS...

#navbar-el {
  display:flex
  align-items: center;
  justify-content: center;
}

To fix this, simply remove the `display:flex' property. Also double-check that you are targeting the correct element for the toggler.

Answer №3

To ensure responsiveness, make use of the navbar-expand-lg class.

<nav class="navbar navbar-expand-lg navbar-dark bg-dark" id="big-bar">

The navigation bar is created by applying the .navbar class, along with a collapsing class that adapts to different screen sizes: .navbar-expand-xl|lg|md|sm (which rearranges the navbar layout for extra large, large, medium, or small screens).

For more information, you can visit: https://www.w3schools.com/bootstrap4/bootstrap_navbar.asp

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

Cities cannot be obscured by a rotating globe

In my latest project, I have created a jsfiddle showcasing a Bostock spinning globe implementation. After successfully plotting a few city markers, I encountered a problem where not all cities were being displayed. Additionally, the script intended to hid ...

Exploring the options available for setting types in Angular-formly

While using setType to create a new type in angular-formly, how can I show the options in the template? I am trying to create a type called "category" that will display the label on the webpage. How can I retrieve the label name? This is what my code loo ...

Set boundaries for square dimensions and placement within the parent container

Struggling to confine a square within specific size constraints while keeping it neatly aligned within the parent container. Balancing these requirements has proven challenging. The layout consists of a main div with two columns on the left and a div occu ...

How come my database is not receiving the data from the first name field?

I have encountered an issue with my comment form where the first name field data is not getting sent to the database along with the comments. I have already checked that the 'first_name' column exists in the database, but still facing this proble ...

`amqplib - What is the current number of active consumers on the queue?`

Seeking insight on using the amqplib module for Node JS and RabbitMQ: 1) Is there a method to determine the number of subscribers on a queue? 2) What is the process for ensuring that each queue has only one consumer key? Appreciate any guidance! ...

What could be causing the linter in vue js to not properly lint the template?

I'm struggling to get the linter to properly lint the template section of my .vue files. Any suggestions on how I can configure this? Basically, I want the linter to format something like this: <template> <v-container> <h1>Ho ...

iPhone: Fixed position div disappearing

Currently, I am working on creating a mobile menu for my Joomla 3 site located at . The menu is functioning correctly on desktops, however, when attempting to view it on my iPhone, the menu slides in but remains invisible. Despite this, I can still tap on ...

Tips on preserving CSS modifications made in Chrome Developer Tools Inspector to .vue file

Currently, I am in the process of setting up a new workflow where my goal is to streamline my work by using the Chrome DevTools Inspector to save any CSS changes directly to my .vue file. While the DevTools Workspaces feature can achieve this, it involves ...

What do cross-domain requests, cross-domain attacks, and cross-domain protocols entail?

Can anyone provide clarification on the concepts of cross domain requests, cross domain attacks, and cross domain protocols as they relate to the AJAX terminology? ...

Utilizing mobile emulators to optimize the viewport for mobile application development

Are mobile emulators like MITE() able to detect viewport settings? <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"> Can anyone recommend a mobile emulator that does recognize viewport settin ...

Removing all text inside an input field with Vue

I am trying to create a password input field using type 'text' instead of 'password.' <input type="text" v-model="form.password" @input="test" /> <input type="hidden" v-model="form.hiddenPassword" /> As part of my approach ...

What is the method for conducting rspec tests on HTML attributes?

Using Ruby, I have generated the following HTML: <%= link_to "change", "http://gravatar.com/emails" %> which creates this link: <a href="http://gravatar.com/emails">change</a> However, I want to make sure that the link opens in a new ...

Issue: JavaScript code is not functional when operating on data obtained through an Ajax

I am experiencing an issue with my JavaScript code (abc.js) that is designed to run on a div element with the class of "one". While the script works perfectly fine on elements already present within the div in the HTML code, it fails to execute on data tha ...

What is the best way to switch the site header in JavaScript or jQuery?

I have created a Bootstrap menu design and I am looking to add a sliding functionality to it. My goal is to hide the menu when scrolling down and display it when scrolling up (slide-down / slide-up). For implementing this feature, I plan to utilize jQuery ...

Taking a Breather with mywindow.print()

I'm currently utilizing a fantastic printing script that I found: <script type="text/javascript"> function PrintElem(elem) { Popup($(elem).text()); } function Popup(data) { var mywindow = window.ope ...

Navigating on Blogger can be a tricky task when it comes to searching and

I recently added a Table to my blogger post, along with an input form for readers to easily search data. After finding the code on W3Schools (link here), I implemented it successfully. However, I am looking to make some improvements. Here is my question: ...

Troubleshooting a problem with a personalized webkit scrollbar in Chrome

Using the CSS property scroll-snap-type: y mandatory; to customize my scrollbar with the following styles: ::-webkit-scrollbar { width: 12px; background: transparent; } ::-webkit-scrollbar-track { background-color: rgba(0, 0, 0, 0.5); -webkit-box-s ...

In order to format my text, I must locate a specific character and encompass the text following it with HTML tags

When working with a list generated in Jekyll, I came across the need to emphasize certain words using strong tags. My solution was to incorporate a delimiter into the process. <li>100g of |sugar</li> This would transform into: <li>100g ...

Is there a way to generate random numbers that will create a chart with a general upward trend?

Are you looking for a solution to generate random numbers for charts that trend upwards and to the right? I am currently utilizing a JavaScript charting engine, so I will require numbers in JSON format eventually. However, I am open to alternative methods ...

Having trouble making setTimeout work with a nested function in it

I've encountered an issue with the setTimeout() function. Take a look at my code snippet below: $('#start').click(function(event) { var result = Math.floor(Math.random() * (10000 - 4000 + 1)) + 4000; // generates a random value between ...