Ways to solve the issue of the mobile dropdown menu in Bootstrap

Check Out the Expected Look Here (Image link)

See How it Appears on Mobile Devices

The dropdown menu causes an increase in the size of the navbar on the mobile version.

Below is the code snippet:

<div style=" background-image: url(https://i.imgur.com/408H5PI.jpg); background-size: cover; height: 100vh; background-attachment: fixed;">
<div class="sticky d-inline">
<!--Navbar Start-->
<nav class="navbar navbar-expand-lg navbar-light fixed-top" style="background: #285123; position: static;">
    <a class="navbar-brand" href="/"><img src="https://i.imgur.com/ui7PG0R.png" alt="text bajo" width="50px" height="50px"></img></a>
    
    </button>
    <div class=&q ` uot ;navbar-expand-lg" id="navbarNavDropdown">
      <ul class="navbar-nav navbar-expand-lg">
        
        
        <li class="nav-item dropdown float-right navbar-expand-lg">
          <a class="nav-link dropdown-toggle text-light" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            Category
          </a>
          <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
            {% for Category in category%}
            <a class="dropdown-item" href="{{url_for('get_category', id=Category.id)}}">{{Category.name}}</a>
            {% endfor %}
          </div>
        </li>

        
      </ul>
    </div>
     
    
  </nav>
</div>

Answer №1

It's designed to function that way, following the navbar style.

To avoid this issue, include position-absolute in the dropdown-menu class to prevent it from affecting the parent container. However, this may cause the menu to extend beyond the container, so also add dropdown-menu-right to confine it within.

(you can customize it by aligning left on desktops and right on mobile using

dropdown-menu-sm-right dropdown-menu-lg-left
)

Give this a try:

<div style=" background-image: url(https://i.imgur.com/408H5PI.jpg); background-size: cover; height: 100vh; background-attachment: fixed;">
<div class="sticky d-inline">
<!--Navbar Start-->
<nav class="navbar navbar-expand-lg navbar-light fixed-top" style="background: #285123; position: static;">
    <a class="navbar-brand" href="/"><img src="https://i.imgur.com/ui7PG0R.png" alt="text bajo" width="50px" height="50px"></img></a>
    
    </button>
    <div class="navbar-expand-lg" id="navbarNavDropdown">
      <ul class="navbar-nav navbar-expand-lg">
        
        
        <li class="nav-item dropdown float-right navbar-expand-lg">
          <a class="nav-link dropdown-toggle text-light" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            Category
          </a>
          <div class="dropdown-menu position-absolute dropdown-menu-sm-right dropdown-menu-lg-left" aria-labelledby="navbarDropdownMenuLink">
            {% for Category in category%}
            <a class="dropdown-item" href="{{url_for('get_category', id=Category.id)}}">{{Category.name}}</a>
            {% endfor %}
          </div>
        </li>

        
      </ul>
    </div>
     
    
  </nav>
</div>


<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="40222f2f34333432213000746e766e72">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">


<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8de7fcf8e8fff4cdbea3b8a3bc">[email protected]</a>/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3f5d50504b4c4b4d5e4f7f0b1109110d">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct" crossorigin="anonymous"></script>

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

I am unable to access the Xml data using VBA's `selectsinglenode` function as it is returning nothing

Below is the XML data: <NewZipCdListResponse> <cmmMsgHeader> <requestMsgId/> <responseMsgId/> <responseTime>20220526:085103847</responseTime> <successYN>Y</successYN> <returnCode>0 ...

Endless scrolling feature malfunctioning

On my profile_page.php, the default setting is to display 10 posts (10 rows from the database) for the user. If a user has more than 10 posts, and scrolls to the bottom of the page, the div should expand to reveal the remaining posts (maximum of 10). For e ...

Showing information retrieved from a database using PHP in a sequential manner

I'm currently working on developing a webpage that features 6 rows of images, with each row containing 4 images accompanied by captions right below them. The structure I have in mind is as follows: IMAGE IMAGE IMAGE IMAGE TEXT TEXT TEXT TEXT IMAGE ...

I am experiencing difficulty with my grid as it refuses to center elements

Hello everyone, this is my first post here. If I missed any important information or didn't present things correctly, please feel free to let me know. I'm currently a developer in training and recently had to work on my first website project aft ...

Get notified about the number of cells you've selected by simply dragging on a table

Is there a way to display the number of selected cells in a table when dragging with the mouse? I have a table set up, and I'd like to create an alert that shows how many cells are selected while dragging. Here is the link to my fiddle: http://jsfiddl ...

Seeking guidance on implementing toggle buttons for navigation bar items on mobile screens, enabling them to toggle for a dropdown menu. The tools at my disposal are HTML, CSS

I want to make the navigation menu responsive by adding a toggle button for the dropdown menu on mobile screens. Here is the code snippet: .nav-link { display: inline-block; position: relative; color: black; } html,body{ height: 100%; width ...

Button for browsing weekly recipes in HTML table format

Seeking assistance in creating a dynamic weekly recipe webpage using HTML and CSS. The goal is to have a form where users can submit a recipe, which will then be added to a specific day of the week in a table displaying all recipes for that day. Can someon ...

What is preventing my div from reaching 100% height when I implement an HTML5 doctype? Is there a solution to achieving a full height div?

I'm currently working on organizing the layout for a basic gallery webapp, and I've encountered an issue where some of my divs are shrinking in height when using an HTML5 doctype declaration. Despite trying different CSS properties, I can't ...

JavaScript - Error encountered when accessing information from elements in the DOM

Just started learning javascript and encountering a problem that I can't seem to solve. I'm attempting to assign the className of a <div> element to a variable, but I keep receiving this error message: scripts.js:30 Uncaught TypeError: Can ...

The alignment of the submit button is consistently off when placed alongside two input boxes within a table

Completing this task is usually straightforward. I have a sign-in form with an email input, password input, and submit button aligned horizontally. However, after trying various styles and structures for hours, the button appears slightly lower than the in ...

What types of events can be used to trigger the start of HTML5 audio playback in mobile Chrome?

When it comes to mobile browsers, Audio elements require user action before play can start. The click event usually satisfies this requirement, but touchstart doesn't seem to be an acceptable initiating event in Chrome on Android or iOS. (Refer below ...

Including content without triggering the digest cycle (utilizing raw HTML) within a Directive

My goal is to include raw HTML inside a directive for later transclusion (to populate a modal when opened). The issue arises when the contents of dialog-body are executed, triggering the ng-repeat loop and causing the template to be rerun, leading to a po ...

Toggle jQuery to hide a div and update its CSS styling

There is an anchor with the class of "hide-btn1" that I want to trigger a series of actions when clicked: The rcol-content should hide and the text should change from Hide to Show The #container width needs to increase to 2038px The table.status-table wi ...

Targeting the landscape mode on screens of both iPhone 4 and iPhone 5 sizes using CSS3 Media Queries

I'm facing a problem with CSS3 media queries while developing a mobile site. The code I've written works perfectly on the landscape mode of an iPhone 5, but it's not quite right on an iPhone 4 or earlier in landscape mode. /* Default stylin ...

Chrome is the only browser that displays the correct number of columns, unlike IE and Firefox

[Link removed] Is anyone else experiencing an issue with the columns on a website layout? I have 5 columns set up with each post taking up 20% width. It looks fine in Chrome, but in IE and Firefox, the last column gets pushed below so there are only 4 col ...

The interaction of flex-box in the presence of absolute positioning

Hey everyone, I need some help understanding why the flexbox is behaving oddly in this code snippet. 1. <!DOCTYPE html> <html> <head> <style> body{ position: relative; } .container { ...

What is causing the navigation bar object to not adhere to the CSS rules?

My presentation for the MVP is outlined below: .navbar { flex-direction: row; } <!DOCTYPE html> <html lang="en" dir="ltr> <head> <meta charset="utf-8"> <title></title> <link rel="stylesheet" href="h ...

How to Retrieve the Current div's ID in VueJS

When using the v-for directive to dynamically generate an id for my div, I need to pass this unique id to a specific function. <div v-for="(item, index) in items" :key="index" :id="'form' + index" > ...

Determining if a component is nested within itself in Angular 6 is a crucial task

My goal is to develop a custom Angular component for a nested navigation menu with multiple levels. Below is an example of how the menu structure looks: app.component.html <nav-menu> <nav-menu-item>Section 1</nav-menu-item> <nav- ...

How can I transform an HTML element into a textarea using CSS or JavaScript?

While browsing a webpage, I discovered a <div> element with the class .plainMail and I want to find a way to easily select all its text by simply pressing Ctrl+A. Currently using Firefox 22, I am considering converting the div.plainMail into a texta ...