The navigational scroll feature in Bootstrap's horizontal dropdown menu is not functioning properly

Today, I encountered an issue with Bootstrap while using a horizontal dropdown menu. It seems that the menu won't scroll with my navbar, and the culprit appears to be this particular CSS class:

.dropdown-menu {
    width: 100%;
    position: fixed;
    top:210px;
    z-index: 1000;
    display: none;
    float: left;
    text-align:center;
}

However, removing or modifying the position:fixed property causes my dropdown menu to change back to a vertical alignment...

HTML

<div class="logo"><a href="#"><img src="img/logo.jpg" alt="logo"></a></div>
<nav class="navbar navbar-inverse" role="navigation">
    <div class="container-fluid">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
        </div>

        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <li><a href="#">mmenu1</a></li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">mmenu2</a>
                    <ul class="dropdown-menu" role="menu">
                        <li><a href="#">smenu1</a></li>
                        <li><a href="#">smenu2</a></li>
                        <li><a href="#">smenu3</a></li>
                        <li><a href="#">smenu4</a></li>
                        <li><a href="#">smenu5</a></li>
                        <li><a href="#">smenu6</a></li>
                    </ul>
                </li>
                <li><a href="#">mmenu3</a></li>
            </ul>
        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>

CSS

.logo{
    text-align:center;
}
.navbar .navbar-nav {
    font-size:1.9em;
    font-family:verdana;
    display: inline-block;
    float: none;
}
.navbar-inverse .nav > li{
    display:block;
}
ul.nav li.dropdown:hover ul.dropdown-menu{
    display: block;
}
.navbar .navbar-collapse {
  text-align: center;
}
.navbar-inverse .nav > li{
    width:170px;
    display:block;
}
.dropdown-menu {
    width: 100%;
    position: fixed;
    top:210px;
    z-index: 1000;
    display: none;
    float: left;
    text-align:center;
}
.dropdown-menu li {
    display:inline-block;
}

Check out the code in action on Bootply: http://www.bootply.com/cmjcUyHRTw

Any suggestions on how to solve this issue?

Answer №1

The issue at hand lies in the fact that width: 100% behaves differently depending on whether the position is fixed or absolute. When it's set to fixed, it will take up 100% of the window width. However, when it's set to absolute, it will take up 100% of its nearest parent element with relative positioning.

In this scenario, the li.dropdown element has relative positioning, causing the dropdown to inherit that width. To resolve this, simply add the following line of CSS:

ul.nav li.dropdown {position: static;}

To properly adjust your dropdown menu CSS, use the following lines:

.dropdown-menu {
    position: absolute;
    top:50px;
}

You can view the updated bootply here: http://www.bootply.com/EuiK4NsMn5

Answer №2

The issue lies with the width:100% in the .dropdown-menu class, as it is only expanding to 100% of the li element's width, not the entire page.

To solve this problem, try removing the position fixed and adding the following CSS:

.dropdown-menu {
    width: 600px;
}

Additionally, include the following CSS:

.dropdown-menu li {
    display:block;
    float: left;
}

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

Streamlining form submission processes with VBA automation of check box selections

Currently, I am facing a challenge with automating the process of filling out a web form using VBA. Specifically, I have hit a roadblock when it comes to selecting a checkbox in the form before proceeding. Here is the HTML code pertaining to the checkbox: ...

Why isn't my heading showing up as expected in my document?

Can anyone help me understand why my title appears so low on certain screens? I've previously tried removing the negative margin when the title was hidden, but now it's positioned too far down. Here is the link to my webpage: ...

How to refresh a webpage using Node.js and the HTML <select> element

When I choose a category from the drop-down menu, I want the page content to be updated with items from that category. I have two files: one for routing and the other is the .ejs file that contains the select option and item cards. listingRouting.js: Th ...

When you apply margins in CSS and HTML, it can cause elements to break out of the row alignment

I'm struggling with my html code that contains elements arranged in rows: <div class = "row"> <div class="col-sm-3 cont-box"> <h1>Title1<h1> </div> <div class="col-sm9 cont-box"> <img src="onepic.jpeg" class=" ...

The dynamic php form features a single set of buttons labeled Next and Before for easy navigation

I am in the process of creating a dynamic form using a single PHP file that displays and saves data from an SQL database. I now want to add two buttons, NEXT and BEFORE, but I have been having difficulty getting them to display or navigate to the next/prev ...

Adjusting label color when input is deactivated in a React application using TypeScript

Is there a way to change the label color in my view when the input is disabled using Typescript or CSS? This is the interface I am working with: interface image Here is the code snippet: <tr> <td className="name">Critère d&a ...

Rows intersecting and stacking above one another

I designed a layout with some text and icons displayed in rows. While it appears properly on iOS, the rows overlap on Android. const criteriaList = [ { id: 0, title: 'Noor', checked: false }, { id: 1, title: 'Friends & Grades', ...

"What's the best way to make sure a checkbox stays checked and its content remains visible after a

After updating my HTML content, it now consists of a hidden table inside a div with the class "myClass": <div class="myClass" style="display:none"> <table class="table table-hover"> ..... </table> </div> The table remains hidden u ...

Unresponsive Button_tag within a Rails table

The situation is as follows: I have a button_tag located within a form that is nested inside a table: <div class="table-responsive tableBG"> ** Interestingly, the button functions perfectly when placed here ** <table class="table table-striped ...

Using jQuery to replace an HTML element multiple times

Seeking assistance for implementing functionality that replaces a button with an input field, where users can enter information and hit enter. Once the action is completed, the original button should reappear. The current script works effectively but lacks ...

Conceal Navigation Panel while Scrolling Down, Reveal when Scrolling Up, Compatible with Chrome, Incompatible with Safari (on smartphones

I have implemented a code to hide my navbar when scrolling down and show it when scrolling up. This code works perfectly on desktop and in all browsers, including Chrome on mobile (iPhone). However, in Safari, the navbar sometimes shows, hides, and shows a ...

In Java using Selenium, I am able to retrieve the text of an element but experiencing difficulty clicking on its link

I am encountering difficulties with clicking on a link within a webpage using the Selenium webdriver on Firefox. Below is a snippet of the code related to the issue: WebElement option = driver.findElement(By.id("AccNumSpan" + i)); if(opt ...

"Retrieve the position of a contenteditable element while also considering HTML

I've been exploring a method to generate annotations within HTML text using JavaScript. The approach involves the user clicking on a contenteditable <div> and obtaining the cursor's position based on their click. Subsequently, when insertin ...

Having trouble displaying image using absolute path in Express

Currently, I am developing a NodeJS application and have encountered an issue with a div element that has a background-image set in an external CSS file. Surprisingly, the CSS file functions perfectly when tested independently, and the background image dis ...

Translucent tonal backdrop hue

Is there a creative solution to dynamically increase the width of a border up to a certain point, using the thickness of the border as a progress bar indicator while reusing defined colors in stylesheets? Currently, I have the element with the border nest ...

Enhance Your Website with HTML5 Video Transition Effects

Is it possible to recreate video transition effects using HTML5 similar to the ones shown in this example: Can this be achieved across all major browsers, including Safari, Firefox, Chrome, and IE9? ...

Choosing and adding a div to another using the select method

Can someone assist me with this task? My goal is to dynamically append a div when selecting an option from a dropdown, and hide the div when the same option is selected again. Additionally, I want the name of the selected option to be displayed on the left ...

stylized tables with assorted colored categories

Here is the layout of my table: Grade Sign StudentGrade 6 + 1 6 0 6 - 0 5 + 0 5 0 5 - 0 4 + 0 4 0 4 - 1 3 + 0 3 ...

Expanding the padding of a span element without displacing the text inside

I'm looking to enhance a span with highlighted text, complete with some padding, while ensuring the surrounding text in the div stays put. Currently, the padding seems to work vertically (with the edge of my span overlapping lines above and below) but ...

What is the best approach for looping through nested structures in Go?

When I attempt to iterate over a list of data enclosed in Curl brackets, I receive an error message stating "Range Can't iterate over....list of data." The struct I am working with is as follows: type FamilyMembers struct { XMLName xml.Name ...