Creating a solo horizontal navigation bar with Bootstrap 4

I am trying to create a horizontal navbar with three nav-pills that are all the same size.

However, when I switch to a smaller screen resolution (iPhone 5), the third item always moves to a new line and expands to full width.

How can I make sure that the layout remains in a single line for all reasonable resolutions?

I did manage to achieve it by changing py-1 class to py-0, but I prefer the look of additional padding.


    <div class="container-fluid">
        <section class="container py-1">
            <div class="row">
                <div class="col-md-12 align-content-center">
                    <ul class="nav nav-pills nav-fill navtop">
                        <li class="nav-item px-1 ">
                            <a class="nav-link active " href="https://example.com/home">Home</a>
                        </li>
                        <li class="nav-item px-1 ">
                            <a class="nav-link active " href="https://example.com/meetings">Meetings</a>
                        </li>
                        <li class="nav-item px-1 ">
                            <a class="nav-link active " href="https://example.com/courses">Courses</a>
                        </li>
                    </ul>
                </div>
            </div>
        </section>
    </div>

Answer №1

It appears that there are unnecessary containers in your code -

I have removed those extra containers and included additional CSS for padding (feel free to customize/remove as needed)

Update:

In response to the OP's feedback, I have adjusted the left/right padding of the container from 15px to 5px to accommodate pills on smaller resolutions like iPhone 5/SE - refer to the image below

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

Check out the demo below!

/* Adds padding to the left and right of each menu item */

.nav-pills li.nav-item {
  padding: 0 2px;
}

.container-fluid {
  padding-right: 5px !important;
  padding-left: 5px !important;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.0/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.0/js/bootstrap.min.js"></script>

<div class="container-fluid">
  <ul class="nav nav-pills nav-fill navtop">
    <li class="nav-item">
      <a class="nav-link active" href="https://example.com/home">Home</a>
    </li>
    <li class="nav-item">
      <a class="nav-link active" href="https://example.com/meetings">Meetings</a>
    </li>
    <li class="nav-item">
      <a class="nav-link active" href="https://example.com/courses">Courses</a>
    </li>
  </ul>
</div>

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

The smooth transition of my collapsible item is compromised when closing, causing the bottom border to abruptly jump to the top

Recently, I implemented a collapsible feature using React and it's functioning well. However, one issue I encountered is that when the collapsible div closes, it doesn't smoothly collapse with the border bottom moving up as smoothly as it opens. ...

I want to create CSS columns that stretch to the full height of the window, positioned between a header and a footer, while also

I am looking to create a basic HTML layout with CSS that includes a header and two columns. The right column should have a fixed width of 100px, while the left column may have varying content lengths. I want both columns to stretch to the footer. Below is ...

I am encountering an issue with image sliding when trying to implement it within a ViewBag foreach loop in ASP.NET

I'm currently working on a project that involves displaying images in a slideshow with accompanying text. However, I've encountered an issue where all the images are being displayed in a single line, one after another, instead of looping through ...

Utilizing FontAwesome icons instead of png images as a visual source

Is there anyone who can assist me? I currently have SiteSearch360 set up on my website with a full screen search bar that is activated by clicking on an image of a magnifying glass. My goal is to replace the default image (src="https://cdn.sitesearch360. ...

Expansive dropdown menu stretching across the entire width, yet the content within restricted to a width of

I have recently made some updates to our website's dropdown menu, expanding the results displayed. However, I would like the dropdown contents to fit within the width of our page. https://i.sstatic.net/aR0Qm.jpg https://i.sstatic.net/e61Ig.jpg I ha ...

Having trouble with the Bootstrap 5 Dropdown menu, not sure what's causing the issue

I have included my code below, however, I am encountering an issue with the dropdown menu not dropping regardless of what I press. At this moment, I do not have a main.js file in place. Below is the code snippet: <!DOCTYPE html> <html lang=" ...

Troubleshooting Issue with Importing File into CSS Document

I'm currently working on building a website and I've been trying to import an image to use as the header. I want to add this .png picture to my CSS file, but despite extensive research and double checking everything, I still can't figure out ...

Showing computation result on a separate column in an HTML table

I am trying to set up a table with 3 columns. One column, total_column_price, is intended to display the calculation result of amount and device_price. How can I achieve this? The Table {{ Form::open(['action' => 'TransactionsINCont ...

Retrieve data from an HTML form within an Angular 2 ag-grid component

I'm facing a challenge with incorporating form values from a modal into an ag-grid array in my HTML file. I'm unsure of the process to achieve this. Below is an excerpt from my file.html: <template #addTrainContent let-c="close" let-d="dismi ...

`Error with Bootstrap breakpoints in mobile display`

While working on a responsive login layout using Bootstrap 5, I encountered a strange issue. The design looked fine in the web view, but when switching to mobile view, the md and sm breakpoints didn't trigger as expected. However, after pasting the co ...

Tips for preserving component state during page rerenders or changes

I created a counter with context API in React, and I'm looking for a way to persist the state even when the page is changed. Is there a method to store the Counter value during page transitions, similar to session storage? My app utilizes React Router ...

Ensure that the body content is completely transparent upon loading the page, except for a specific div within the content that remains

Currently, I am experimenting with JQuery and my goal is to have the body content of a webpage appear transparent upon loading, with the exception of one specific div that should remain opaque. So far, this is what I've accomplished ... <!DOCTYPE ...

The modification of HTML styles

How can I change the style (width, color etc) of all 8 functions like this? function my(){document.getElementById("question1").innerHTML="THIS QUESTION"+ "<br>" +"<button onclick=answer1() id=ques1 >first answer</button>" +"<button ...

I am currently facing challenges in successfully setting up my title and ensuring that the menu animation runs smoothly and works effectively

I'm struggling to solve these basic problems: 1. The text animation in the menu disappears when closing it, but I want it to appear like it does when opening. 2. I need the menu header text animation to be delayed so it doesn't overlap with the ...

Setting Aggrid style height to 100% in JustPy made easy

I am attempting to adjust the Aggrid height style to 100%, but unfortunately, the table is not displaying as expected. I have tried using viewport and pixel measurements, which worked fine. Interestingly, percentage width is working perfectly well. My goa ...

Remove Vue Component from the styling of current application

We integrated a Vue component (using Vuetify) into our existing .NET MVC application. The issue we are facing is that the Vue component is inheriting all the CSS styles from the rest of the application. Here's a simplified version of the HTML structur ...

How can I integrate JavaScript into Django in order to execute three separate functions?

I stumbled upon this question that seems like it could solve my issue, however, I lack knowledge in javascript. In my views.py file, I have 3 functions that I want to execute, but due to using (forms.Form), I am facing difficulties running these functions ...

Is there a way to customize the hover effect on this navigation link in Bootstrap that includes a span and an icon from Bootstrap?

<li class="nav-item mt-3"> <a href="#" class="nav-link px-2 d-flex justify-content-start align-items-center"> <i class="nav-icon bi bi-calculator-fill fs-4"></i> ...

During DragAndDropToObject in Selenium IDE, the initial element in the list is overlooked

I have a webpage that is split into two datagrids. The left datagrid is structured like this: <ul class="left_dg"> <li> <ul></ul> </li> <li> <ul></ul> </li> <li&g ...

Ways to Extract HTML DOM Attributes using Jquery

I am working with an HTML DOM that is saved in a JavaScript Variable. I need to figure out how to retrieve its attributes. For example: <script> //element_html is ajax response var element_html = '<h1 style="" class="app-control " data-order ...