Designing a responsive navigation bar with slide functionality for both web and mobile interfaces utilizing Bootstrap

I have integrated Bootstrap 4.5.0 with the necessary CSS and script from the CDN on my webpage. I am attempting to create a responsive navigation bar header similar to the one on the Bootstrap website, which functions effectively on both desktop web browsers and mobile devices. However, I am facing challenges in implementing a feature where the navbar list items can be scrolled or slid from left to right and vice versa on a mobile device or small screen.

The Bootstrap header on a small screen appears as follows:

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

The above image of the Bootstrap site showcases items like Home, Documentation, ..., and Themes that can be scrolled left to right and back by using the mouse (on desktop) or finger (on a mobile device).

Take a look at the image below after dragging Themes to the left:

https://i.sstatic.net/3fyNe.png

I am encountering difficulties in achieving this functionality with my code and Bootstrap. Here is the code snippet:

            <header class="navbar navbar-expand navbar-light flex-column flex-md-row bd-navbar" style="background-color: yellow;">
                <a class="navbar-brand" href="#">Navbar</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="navbar-nav-scroll">
                    <ul class="navbar-nav bd-navbar-nav flex-row">
                        <li class="nav-item active">
                            <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
                        </li>
                        <li class="nav-item active">
                            <a class="nav-link" href="#">Start&nbsp;Test</a>
                        </li>
                        <li class="nav-item active">
                            <a class="nav-link" href="#">Testaaa</a>
                        </li>
                        <li class="nav-item active">
                            <a class="nav-link" href="#">Testbbb</a>
                        </li>
                        <li class="nav-item active">
                            <a class="nav-link" href="#">Testccc</a>
                        </li>
                        <li class="nav-item active">
                            <a class="nav-link" href="#">Testddd</a>
                        </li>
                        <li class="nav-item active">
                            <a class="nav-link" href="#">Testeee</a>
                        </li>
                    </ul>    
                </div>
            </header>

At present, my code lacks the slide functionality, and I would appreciate some assistance in identifying the missing elements. Thank you.

Answer №1

The sliding effect in your code is working correctly because you have included the necessary 2 CSS paths. It seems like everything is setup properly.

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<link rel="stylesheet" href="https://getbootstrap.com/docs/4.5/assets/css/docs.min.css">

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<link rel="stylesheet" href="https://getbootstrap.com/docs/4.5/assets/css/docs.min.css">

<header class="navbar navbar-expand navbar-light flex-column flex-md-row bd-navbar" style="background-color: yellow;">
  <a class="navbar-brand" href="#">Navbar</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="navbar-nav-scroll">
    <ul class="navbar-nav bd-navbar-nav flex-row">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item active">
        <a class="nav-link" href="#">Start&nbsp;Test</a>
      </li>
      <li class="nav-item active">
        <a class="nav-link" href="#">Testaaa</a>
      </li>
      <li class="nav-item active">
        <a class="nav-link" href="#">Testbbb</a>
      </li>
      <li class="nav-item active">
        <a class="nav-link" href="#">Testccc</a>
      </li>
      <li class="nav-item active">
        <a class="nav-link" href="#">Testddd</a>
      </li>
      <li class="nav-item active">
        <a class="nav-link" href="#">Testeee</a>
      </li>
    </ul>
  </div>
</header>

Answer №2

Below is the solution, please test it on the mobile view of your browser. I have utilized both overflow:hidden and overflow-x:auto to ensure functionality.

 .bd-navbar {
 box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, .05), inset 0 -1px 0 rgba(0, 0, 0, .1);

 }
 .bd-navbar .navbar-nav .nav-link.active, .bd-navbar .navbar-nav .nav-link:hover {
 color: white!important;
 background-color: transparent;
 }
 
 @media all and (max-width: 991px) {
 .bd-navbar {
 padding-right: 0.5rem;
 padding-left: 0.5rem;
}
 .bd-navbar .navbar-nav-scroll {
 max-width: 100%;
 height: 2.5rem;
 margin-top: 0.25rem;
 overflow: hidden;
}
 .bd-navbar .navbar-nav-scroll .navbar-nav {
 padding-bottom: 2rem;
 overflow-x: auto;
 white-space: nowrap;
 -webkit-overflow-scrolling: touch;
}
}

 
 
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<header class="navbar navbar-expand navbar-light flex-column flex-md-row bd-navbar" style="background-color: yellow;">
                <a class="navbar-brand" href="#">Navbar</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="navbar-nav-scroll">
                    <ul class="navbar-nav bd-navbar-nav flex-row">
                        <li class="nav-item active">
                            <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
                        </li>
                        <li class="nav-item active">
                            <a class="nav-link" href="#">Start&nbsp;Test</a>
                        </li>
                        <li class="nav-item active">
                            <a class="nav-link" href="#">Testaaa</a>
                        </li>
                        <li class="nav-item active">
                            <a class="nav-link" href="#">Testbbb</a>
                        </li>
                        <li class="nav-item active">
                            <a class="nav-link" href="#">Testccc</a>
                        </li>
                        <li class="nav-item active">
                            <a class="nav-link" href="#">Testddd</a>
                        </li>
                        <li class="nav-item active">
                            <a class="nav-link" href="#">Testeee</a>
                        </li>
                    </ul>    
                </div>
            </header>

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

Adjusting the desktop view through media queries for mobile devices

As someone with no coding experience, I've been working on my portfolio using Cargo. Currently, I'm trying to adjust the mobile view of an article on my homepage through media queries. However, the code is unintentionally changing the layout on d ...

What is the best way to utilize a single component for validating two other components?

I am encountering an issue with my components setup. I have three components in total: GalleryAddComponent, which is used to add a new element, GalleryItemComponent, used to edit an element, and FieldsComponent, the form component utilized by both GalleryA ...

What is the best way to design unconventional grids using Bootstrap 4?

Is it possible to achieve unique grid layouts in Bootstrap 4? For instance, An irregular grid where the first column covers two rows, followed by two rows with three columns each |||||||||||||||| | | | | | | |_ |_ |_ | | | | | | |_____| ...

How can I achieve a fade-in effect whenever the flag image is clicked?

A unique "international" quotes script has been created, showcasing Dutch, English, German, and French quotes. The script displays different quotes every day, with a draft-result visible in the upper right corner of this page ... The code used for this sc ...

Transform JavaScript code into HTML using jQuery.`

I have a piece of HTML and JavaScript code. The JavaScript code is currently in jQuery, but I want to convert it to vanilla JavaScript: // Vanilla JavaScript code document.querySelectorAll('.hello[type="checkbox"]').forEach(item => { item ...

JavaScript array with more than 4 elements

I am working on a program where I have created an array and now want to display all the words that contain more than 4 letters. Check out my code snippet below: function oppC(){ var ord = ["Apple", "Two", "Yesterday", "mother", "lol", "car", "co ...

Email button designed to trigger the execution of PHP code

Can a hyperlink button in Outlook emails be used to run PHP code? For instance, I've designed a computer request form that appears as follows: New Request When you select the "new request" button, it changes to indicate completion: Completed Reque ...

Developing an interactive contact page using bootstrap technology

I am looking for a way to structure my contact page using Bootstrap. https://i.sstatic.net/e3TCu.png If you're interested, the code for this layout can be accessed here: https://codepen.io/MatteCrystal/pen/xxXpLmK <div class="container" ...

What is the best way to implement a hover effect on multiple rows within an HTML table using Angular?

I am currently working on developing a table preview feature to display events. I previously sought assistance here regarding positioning elements within the table and successfully resolved that issue. Applying the same principles, I am now attempting to c ...

"Facing an issue with Google Chrome not refreshing the latest options in an HTML select dropdown list

Having trouble creating an offline HTML file that incorporates jQuery for the script. The page features a state select menu followed by a second menu for counties. When a state is selected, only the corresponding counties should display while others remai ...

php failure to execute included file

Hey there! I'm currently facing an issue with including a file that contains all of my 'head' information. My goal is to simplify and streamline my page by breaking it down. In my index.php file, here's what I did: <?php include & ...

Tips for adjusting the size of a CSS radio button while ensuring the text remains centered

Uncertain about which part to modify in this radio button code to decrease its size while keeping the text aligned with the inner button. Changes made have shifted the text to the top of the button instead. Can you provide guidance on the necessary adjustm ...

HTMLKit is functioning properly on the simulator but is experiencing difficulties when running on the

Currently, I'm utilizing HTMLKit as a dependency in my project. It runs smoothly on the simulator but encounters issues when running on an actual device. Below is the crash log generated while attempting to run it on an iPhone: dyld: Library not ...

Having trouble with CSS media queries not functioning properly on Internet Explorer version 9?

Incorporated media queries in my design to adjust the width of certain elements on the page according to the browser's width. These are the queries I am using: @media screen and (min-width:1024px) @media screen and (max-width:1024px) Chrome, Safari, ...

Incorporate JavaScript code into an Angular UI-Router view

I can't seem to find an answer to this question anywhere, so I'm hoping someone here can help me out. In my AngularJS app, I am using ui-router to load multiple views into the same <ui-view> element. I am trying to implement Jquery UI&apos ...

What is the best way to set up a loop for displaying Chat Bubbles?

Is there a way to create a loop for chat bubbles? I want them to appear on the right when I send a message and on the left when the chat partner replies. How can I implement this loop? This is the code I currently have: <div class="Webview"> &l ...

Fill the list items with values from the given array

I have an array called var array = ["one", "two"]; and I want to display each element in a separate list item. The desired output is: <li>Number one</li> <li>Number two</li> However, the current output is: <li>Number onetw ...

Transfer a variable from one PHP page to another and navigate between the two pages

I am just starting to learn PHP and I have a scenario where I need to retrieve the last ID from the database. For each ID, I need to fetch the state and the associated link. If the state is equal to 1, then I need to extract some content from the link (whi ...

Tips for modifying the "width" of a style within an HTML template implemented in a NodeJs express application

Currently, I am facing a challenge in dynamically adjusting the width value for a <div> element serving as a coloured bar within an HTML template used for PDF generation. While I can successfully set other values using something like {{my_value}}, ap ...

Modify the Primevue Class p-accordion-header only under certain conditions

I'm currently facing a challenge with customizing the styling of the primevue component class p-accordion-header based on the status of the rendered component determined by the variantNumber. Here's a snippet of my code: <Accordion :multiple= ...