Bootstrap: White space can be seen on the right side of the mobile screen, with an incomplete nav bar

My website, built with Bootstrap, functions properly on desktop and in landscape mode on mobile. However, it encounters issues in portrait mode on mobile where white space appears on the right side and part of the navigation bar is missing.

Below is the code snippet:

<!DOCTYPE html>
<html lang="en">
  
  <head>
    {% load static %}
         <!-- Latest compiled and minified CSS -->
    
    <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="274548485354535546576712091709170a4542534615">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
    <link  rel="stylesheet" type="text/css" href="{% static 'css/main.css' %}">

  
    <!-- jQuery library -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>


    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta charset="utf-8">


  </head>
  
   <body>
      <nav class="navbar navbar-expand navbar-dark bg-dark">
  
         <ul class="navbar-nav navbar-center mb-2 mb-sm-0">
             <li class="nav-item fs-3 mx-5">
                 <a class="nav-link link-color" aria-current="page" href={% url 'homepage' %}>About</a>
             </li> 

             <li class="nav-item fs-3 mx-5">
                <a class="nav-link link-color" aria-current="page" href={% url 'gallery' %}>Gallery</a>
             </li> 

             <li class="nav-item fs-3 mx-5 ">
                <a class="nav-link link-color" aria-current="page" href={% url 'guestbook' %}>Guestbook</a>
             </li>
        </ul>

  
     </nav>
     {% block content %}{% endblock %}


    <!-- Latest compiled JavaScript -->
    <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a3c1ccccd7d0d7d1c2d3e3968d938d938ec1c6d7c291">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-b5kHyXgcpbZJO/tY9Ul7kGkf1S0CWuKcCD38l8YkeH8z8QjE0GmW1gYU5S9FOnJ0" crossorigin="anonymous"></script>
   </body>
</html>

This issue persists across all pages of my website as it acts as the wrapper for them.

Here's a glimpse at my stylesheet:


.img-shrink-100 {
  object-fit: contain; 
  object-position: center; 
  height: 100px;
}
.img-shrink-250 {
  object-fit: contain; 
  object-position: center; 
  height: 250px;
}
.img-shrink-700 {
  object-fit: contain; 
  object-position: center; 
  height: 700px;
}

.p-small {
  font-size: 25px;
}

.navbar-nav.navbar-center { 
  margin: auto;
        } 

.link-color{
  color: #FFF !important;
}
.link-color:hover {
  background-color : #999999;
  color : white !important;
}
.form-center {
  text-align: center;
}
.form-oneline{
  display: inline-block;
}

Some users have suggested using overflow-x:hidden to address the white space issue, but this hasn't rectified the cut-off navbar problem (it simply prevents scrolling). As CSS isn't my forte, I'm seeking insights on how to tackle this challenge. Any thoughts?

Answer №1

Your code is experiencing an issue because you are using navbar-expand instead of pairing it with either -lg or -sm.

To resolve this, consider updating your code like so:

<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
  
         <ul class="navbar-nav navbar-center mb-2 mb-sm-0">
             <li class="nav-item fs-3 mx-5">
                 <a class="nav-link link-color" aria-current="page" href={% url 'homepage' %}>About</a>
             </li> 

             <li class="nav-item fs-3 mx-5">
                <a class="nav-link link-color" aria-current="page" href={% url 'gallery' %}>Gallery</a>
             </li> 

             <li class="nav-item fs-3 mx-5 ">
                <a class="nav-link link-color" aria-current="page" href={% url 'guestbook' %}>Guestbook</a>
             </li>
        </ul>
     </nav>

In addition, to make the navbar responsive, ensure you include the code for the toggler/hamburger menu button and Navbar Brand as shown below:

<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
    <div class="container-fluid">

        <a class="navbar-brand" href="#">Navbar</a>

        <button class="navbar-toggler" type="button" data-bs-toggle="collapse"
            data-bs-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 navbar-center mb-2 mb-sm-0">
                <li class="nav-item fs-3 mx-5">
                    <a class="nav-link link-color" aria-current="page" href={% url 'homepage' %}>About</a>
                </li>

                <li class="nav-item fs-3 mx-5">
                    <a class="nav-link link-color" aria-current="page" href={% url 'gallery' %}>Gallery</a>
                </li>

                <li class="nav-item fs-3 mx-5 ">
                    <a class="nav-link link-color" aria-current="page" href={% url 'guestbook' %}>Guestbook</a>
                </li>
            </ul>
        </div>
    </div>
</nav>

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

Loading a div using Ajax within a frame

My php page includes a div that is supposed to be populated by an Ajax call. function showcopay() { var apa = document.getElementById("alert_id").value; $("#copay").load('show_copay.php?pid='+apa); } The parent page of the div used to be ...

WebpackError: The assignment of the property 'emulateTransitionEnd' to an undefined value cannot be completed

I've been attempting to implement Bootstrap in GatsbyJs, but it just seems to continually let me down. Is there a legitimate method to import Bootstrap without encountering the following error? WebpackError: Cannot set property 'emulateTransitio ...

Angular Universal causes SASS imports to malfunction

Check out this sample app that you can download to see the issue in action: https://github.com/chrillewoodz/ng-boilerplate/tree/universal I am currently working on implementing angular universal, but I'm encountering an error with a SCSS import in o ...

Align the bottom borders to the lowest content on each line

I am working on designing my homepage using HTML, CSS, JSP, and JavaScript, focusing on the sale of musical instruments and facilitating communication among users. Right now, I am in the process of creating a site-map for my menu configuration chart using ...

Activate the div when hovering over the span

Experiencing an issue with triggering a visible div while hovering over a span. Here is the code structure: <ul class="products"> <li> <a href="somelink"> <img src="some image"> <div class="overlay"> Some Text</div> & ...

Generate a jQuery iframe once more by requesting it

How can I use jQuery to create an iframe tag and set it as the only content of a specific div? If the target div already has content, I want to replace it with a dynamically created iframe tag. This is what I have attempted so far: $(".someClass").click ...

Ways to increase the spacing between several menus

Need help with spacing between menus Tried using margin left and margin right but it's not working File: _Layout.cshtml <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport&quo ...

What causes the issue of divs not stacking properly when using Bootstrap 4?

I'm currently working on integrating VueJs and bootstrap4 to create two basic components. However, I am facing an issue where I have assigned the class .col-md-4 to a div in order to add 3 elements per row, but only one element is being added per row ...

Initial loading issue with HTML5 Canvas in Android WebView

As I work on developing a HTML5 canvas-based game within a WebView of an existing application, I encounter a puzzling issue. Upon the initial run of the game, everything seems to be in order - logs indicate that it's ready and running, yet nothing is ...

Is it possible to create Android apps using HTML and JavaScript?

I have a strong foundation in HTML, Javascript, CSS, and AJAX, but I want to venture into Android application development. However, I lack knowledge of Java technology. Is it feasible to develop Android apps using HTML or JS? If anyone has experience wit ...

Which is more recommended to use in AJAX (XMLHttpRequest) - eventListener or readyStateChange method?

As I revisited a video from WWDC12 discussing advanced effects with HTML5, I couldn't help but notice that for the demo they utilized req.addEventListener("load",callback,true) instead of the usual onreadystatechange. This made me wonder: what differ ...

Executing a JavaScript/jQuery function on the following page

I'm currently working on developing an internal jobs management workflow and I'd like to enhance the user experience by triggering a JavaScript function when redirecting them to a new page after submitting a form. At the moment, I am adding the ...

Using Four Different Colour Borders in CSS

Is it possible to create a CSS border with 4 different colors on one side? Currently, I have the following: #header { border-color:#88a9eb; } I aim to achieve a border featuring four solid colors split equally at 25% each. Can this be done? I am looking ...

Ways to navigate private property using the App Component in Angular 4

I have successfully implemented code in my app component to retrieve the current URL and display it in app.component.html. app.component.ts import { Component } from '@angular/core'; import { Router } from '@angular/router'; @Compone ...

Simple way to enlarge an image on a webpage with a click

On my website, there is an image that is currently sized at 200x150 pixels. <img src="http://s3-media1.ak.yelpcdn.com/bphoto/sMONYSiLUQEvooJ5hZh0Sw/l.jpg" alt="" width="200" height="150"> Is there a way to implement a feature where visitors can cl ...

Flickering in CSS transitions on Microsoft Edge

There seems to be a peculiar issue with CSS transitions in Microsoft Edge. The problem arises when there is a transition, such as between hover states, but the styles specified for those states are overridden by other styles in the CSS hierarchy. In such ...

What is the best way to distribute javascript and html code across multiple elements on a webpage?

My webpage has a unique feature - two textboxes that trigger a bootstrap modal with a searchable treeview when clicked. The selected item from the treeview automatically populates the textbox. It's a flawless process! Recently, I decided to implement ...

The HTML pattern [A-Za-z] specifies that the entered name must adhere to the required format, such as inputting "john"

<div class="title details"> <label for="idtitle" class="label">Title</label> <input type="text" placeholder="Title" id="idtitle" pattern="[A-Za-z]" required> </div> Link to Firefox screenshot ...

Issues with Bootstrap's navbar-toggleable-sm functionality not functioning properly

Just started learning Bootstrap and following a tutorial on Lynda.com about customizing the navbar. However, despite following the tutorial step by step, my navbar is not behaving as expected - it's stacking vertically on all device sizes instead of j ...

Hiding elements in HTML by setting their display property to "

I'm struggling with this code: <div id="affichageRecherche"></div> <div class="row px-xl-9 d-flex justify-content-start" id="affichageCatalogue">(lot of code)</div> At the bottom of the page ...