Make the Drop-down Menu Background Stretch Across the Entire Width of the Browser

I'm working on developing a unique mega menu that showcases all the contents of each list item. Imagine it as a traditional drop-down menu, but with the twist that all child items are visible upon hover.

I have successfully displayed all the items, but I am facing a challenge in extending the background of the drop-down menu to cover the full width of the browser.

Initially, I attempted to extend the last submenu, but unfortunately, that did not yield the desired results.

Check out the CodePen for the complete code

Here are some code snippets:

HTML

<nav class="main-nav">
      <ul className="nav">
        <li>
          <a>Products</a>

          <div className="subnav-block">
            <ul>
              <li>
                <a>Product A</a>
              </li>
              <li>
                <a>Product B</a>
              </li>
            </ul>
          </div>
        </li>
    </ul>
</nav>

CSS

.subnav-block {
  position: static;
  display: block;
  width: 100% !important;
  top: 54px;
  left: 0;
  opacity: 0;
  visibility: hidden;
  overflow: hidden;
  background: gray;
  -webkit-transition: all 0.3s ease 0.15s;
  -moz-transition: all 0.3s ease 0.15s;
  -o-transition: all 0.3s ease 0.15s;
  -ms-transition: all 0.3s ease 0.15s;
  transition: all 0.3s ease 0.15s;
}

.nav .subnav-block {
  float: none;
  width: 200px;
}

Answer №1

Feel free to customize the styles:

.nav { display:flex; }
.nav > li:last-child { flex: 1; }

You can also create a virtual last menu item to expand the width to maximum:

        <li>
          <a>&nbsp;</a>

          <div className="subnav-block">
            <ul>
              <li>
                <a>&nbsp;</a>
              </li>
              <li>
                <a>&nbsp;</a>
              </li>
            </ul>
          </div>
        </li>

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

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

Is there a way to deactivate or eliminate the alert component?

I'm trying to figure out how to disable the alert in my code, but I can't seem to find a boolean parameter for this in the official documentation. import React from 'react'; import Alert from '@material-ui/lab/Alert'; export ...

Incorporating JavaScript and Alpine.js to Monitor and Log Changes in Input Range Values

I have developed a basic app that logs the input range value to the console when the range input changes. Interestingly, it works flawlessly when I slide the slider left and right with my cursor. However, when I programmatically change the value using Ja ...

Hover effect not displaying upon mouse exit

I am working on a feature where a series of images change when hovered over, with a div animating as an overlay on the image. Here is the code snippet: // hiding overlays initially $(".mini-shop .item .image a div").hide(); // toggling overlay and second ...

Error Encountered when Employing react-redux connect in react-native Development

I have experience using redux with react-dom, but I am facing challenges integrating it into my react-native application. When adding the connect HOC to my component in a simple boilerplate react-native app, I encounter the following error: https://i.sst ...

Safari on iOS 9 having trouble playing embedded YouTube videos

Recently, I discovered that my YouTube embedded videos are not playing on iOS devices when on my website unless you click in the top left corner of the video. Even after removing all extra YouTube parameters and using standard iFrame embed code, the issue ...

Send the typeahead object result from Angular to another function within the controller

In my current setup, I am utilizing the ui-bootstrap typeahead feature to fetch an object from an external API. Upon selecting the object, it triggers a callback function that stores the results in a separate function within my controller. The challenge l ...

The background color in the HTML file remains unchanged

Hello everyone, this is my debut post here. I can't seem to figure out why the background color isn't changing for me. Even though I have applied the bg color property, it's not taking effect as expected. <body bgcolor="#f0ffff"> T ...

Enhancing tabbing accessibility with order classes in Bootstrap 4 for improved navigation

Having trouble with the bootstrap order classes like order-2 order-md-1 in conjunction with tab order for accessibility reasons. My goal is to align the tab flow with the visual flow. Take a look at this code: <div class="row"> <div class="c ...

XML is struggling to load content when using ajax requests

I am attempting to utilize ajax to load an xml file. I have made adjustments to the sample code provided by W3Schools <html> <head> <script> function showBus(str) { if (str == "") { ...

Style the modal body to display as a block on both desktop and mobile devices using CSS

My goal is to ensure that the modal-body is vertically aligned for optimal visibility on both mobile phones and PCs. I am utilizing bootstrap for this purpose. <div class="modal-body" style="display: inline-block;"> <div> ...

In the callback function within Array.prototype.map, make sure to access the newly created array

Array.prototype.map() creates a new array. How can I use this new array within the callback function passed to Array.prototype.map()? For instance: someArray.map(function(item, idx, arr) { return { theCreatedArray: xyz }; }); What should I assign to ...

Styling a Pie or Doughnut Chart with CSS

I am working on creating a doughnut chart with rounded segments using Recharts, and I want it to end up looking similar to this: Although I have come close to achieving the desired result, I am encountering some issues: Firstly, the first segment is over ...

Verify if a set of Radio buttons contains at least one option selected

Need help with validating a Feedback Form using either JQuery or Javascript. The requirement is to ensure that every group of radio-buttons has one option selected before the form can be submitted. Below is the code snippet from form.html: <form id=&ap ...

AJAX function in Chrome console is throwing an error message stating "Unexpected Token }"

Dealing with this issue has been quite unusual for me. I've spent the last 3 days trying to troubleshoot it, but now it's no longer bothering me. The situation involves a button and a textbox that sends the data from the textbox to a PHP page whe ...

Is there a way to connect to a function that has been sent to a child component through a prop in order to invoke it within a function in the child component?

I'm currently facing an issue with accessing the function stored in the closeModal prop that is passed to the child component QRScan. Any advice on how to properly bind and call this function would be greatly appreciated. I attempted to use this.prop ...

Is there a way to include custom headers in the response of socket.io using express.js?

I have been attempting to override the CORS policy using the following code block: app.use('/\*', function (req, res, next) { res.header("Access-Control-Allow-Origin","*") res.header("Access-Control-Allow-Hea ...

Function in AngularJS to increment counts based on matching names

Check out my angular application on this Plunker link The text area in my app contains data in the format of (key, count). My goal is to sum up these values using the calc() function. When the user clicks the button, I want the total summation to be disp ...

Animate the jQuery display property to show a table without changing any specified spatial dimensions

When utilizing jQuery's $.animate() on an element styled with display:table, any spatial dimensions that are not explicitly specified to change will animate. Check out the fiddle here In the scenario presented, the width is defined for animation, bu ...

What is the best method for creating a close button on the bottom right corner with Bootstrap?

I need help adjusting the position of a button in a flash message. How can I move the button to the bottom-right? <div class="alert alert-danger alert-dismissible fade show" role="alert"> <%= success %> ...

Forget the function once it has been clicked

I'm looking for a solution to my resizing function issue. When I press a button, the function opens two columns outside of the window, but I want to reset this function when I click on another div. Is there a way to remove or clear the function from m ...