The navigation bar is not utilizing the entire width of the browser due to the drop-down navigation feature

Hey there! I'm currently working on a dropdown menu using unordered lists and I'm trying to figure out how to make the navigation bar full width without messing up the dropdown functionality.

Whenever I attempt to achieve this by styling the parent div(.menu), I run into overflow issues. My goal is to have the entire menu span the width of the browser window with the text centered within each navigation item. Any help or suggestions would be greatly appreciated. Thanks in advance!

.menu ul {
  list-style: none;
}
.menu ul li {
  width: 220px;
  height: 35px;
  float: left;
  text-align: center;
  background-color: red;
  position: relative;
  list-style-type: none;
  line-height: 35px;
}
.menu ul li a {
  text-decoration: none;
  color: white;
  display: block;
}
.menu ul li a:hover {
  background-color: green;
}
.menu ul ul {
  position: absolute;
  display: none;
}
.menu ul li:hover > ul {
  display: block;
}
.menu ul ul ul {
  margin-left: 220px;
  top: 0px;
}
<div class="menu">
  <ul>
    <li><a href="#">Home</a>
      <ul>
        <li><a href="#">Sub1</a>
        </li>
        <li><a href="#">Sub2</a>
        </li>
        <li><a href="#">Sub3</a>
        </li>
      </ul>

    </li>
    <li><a href="#">Booking</a>
    </li>
    <li><a href="#">History</a>
      <ul>
        <li><a href="#">Sub1</a>
        </li>
        <li><a href="#">Sub2</a>
        </li>
        <li><a href="#">Sub3</a>
          <ul>
            <li><a href="#">Sub1</a>
            </li>
            <li><a href="#">Sub2</a>
            </li>
            <li><a href="#">Sub3</a>
            </li>
          </ul>
        </li>
      </ul>
    </li>
    <li><a href="#">Wrestlers</a>
    </li>
    <li><a href="#">Events</a> 
    </li>
  </ul>

</div>

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

Answer №1

Give this CSS code a try: adjust the width of each menu option to 220px instead of 20%.

.menu ul {
 list-style: none;
 padding-left:0px;
}
.menu ul li {
  width: 20%;
  height: 35px;
  float: left;
  text-align: center;
  background-color: red;
  position: relative;
  list-style-type: none;
  line-height: 35px;
}
.menu ul li a {
 text-decoration: none;
 color: white;
 display: block;
}
.menu ul li a:hover {
  background-color: green;
}
.menu ul ul {
  position: absolute;
  display: none;
}
.menu ul li:hover > ul {
  display: block;
}
.menu ul ul ul {
  margin-left:100%;
  top: 0px;
}

.menu > ul > li > ul {

 width:100%;
}
.menu > ul > li > ul> li {
 display: block;
 width:100%;
}
.menu > ul > li > ul> li > ul {
  width:100%;
}
.menu > ul > li > ul> li > ul > li{
 display: block;
 width:100%;
}

I hope this solution proves helpful :)

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

What causes TypeScript to interpret an API call as a module and impact CSS? Encountering a Next.js compilation error

My website development process hit a roadblock when I tried integrating Material Tailwind into my project alongside Next.js, Typescript, and Tailwind CSS. The compilation error that popped up seemed unrelated to the changes, leaving me baffled as to what c ...

Influencing the movement of one div container using another dynamic div

Apologies for the unclear title. Check out a JsFiddle DEMO to see what I mean. My goal is to move the black container as soon as it touches the red container. I want to prevent the overlap between the two and adjust the position of the red container relat ...

HTML image identifier and canvas elements

Greetings! I have a question that I've been struggling to find an answer for on Google. I'm attempting to draw an image on a canvas and initially used the "new" constructor ( ballPic = new Image(); ballPic.src = "ball.png" ) which worked fine. Ho ...

When I increase the length of my website's header and footer, I notice that the data in the footer is only displayed on the homepage and not on the other

I am facing an issue with extending my header and footer in Django. The problem is that when I pass data to the footer, it only appears on the home page and not on other pages. I understand that I need to pass the data to every page individually, but I am ...

Dynamic Javascript Accordion Navigation Bar Opening and Closing Motion

I'm currently working on a horizontal accordion dropdown navbar and I'm attempting to make it so that only one section can be expanded at a time. For instance, if subsection A is already expanded and you click on section B, then subsection A shou ...

Keep bootstrap content aligned to the left

I am working on creating a webpage using bulma/bootstrap and my goal is to have some text positioned on the left side of the screen. I want this text to be displayed in the red area and to stay fixed in place when I scroll down, similar to a side panel. ...

achieving outcomes beyond iframe boundaries

I currently have an IFRAME that is responsible for loading my login page. Here is the code: <iframe src="loginForm.html"></iframe> Once the form in the IFRAME is submitted, I am looking for a way to retrieve and display the results on the p ...

What steps can be taken to ensure a function operates even when the mouse is stationary?

$(document).ready(function() { var score = 0; $("body").mousemove(function() { score++; $("#result").val(score); console.log(score); }); }); As I move my mouse, the score keeps increasing. But, I'm wonde ...

executing a word macro in real-time using java, html, or jsp

I am a beginner in the world of running macros through coding. I would greatly appreciate any guidance on how to achieve this using either HTML, JSP, or Java. ...

When images in Ionic overlap with the side menu bar

Currently, I am in the process of developing an Android app using the IONIC framework. Within this project, I have created three divisions that contain images with shadows applied to them. However, I am encountering an issue where the side menu bar is over ...

Styling a table based on specific conditions using Angular and JavaScript

I am trying to conditionally style the text in the table based on the time elapsed since the last ping. Specifically, I want to change the color of the text from green to red once 5 minutes have passed and vice versa. <form name="myform" data-ng-submit ...

Tips for successfully passing a Prop using the Emotion CSS function

Passing props through styled() in Emotion is something I'm familiar with. For example: const Container = styled("div")<{ position: string }>` display: flex; flex-direction: ${({ position }) => (position === "top" ? "column" : "row ...

Styling Overlapping Divs with CSS3

I am attempting to replicate this particular effect using HTML within the UIWebView control on iOS. The desired outcome is to simulate a progress bar on the listing. My current approach involved utilizing this method, however, as you can observe, adding pa ...

What is the method for retrieving the input element's value when it loses focus?

I have an input box along with a label. My goal is to apply a specific style to the label whenever there is content in the input box. To achieve this, I need to retrieve the value entered in the input field during the blur event so that I can compare it. & ...

How to organize a python tuple with a mix of strings and numbers

Here is an example list: Items = [('apple 5', 12), ('apple 3', 2), ('apple 6', 10),('apple 4', 15), ('apple 9', 11), ('apple 7', 14), ('apple 18', 10), ('apple 16', 10),(&apos ...

Attempting to alter an image with a click and then revert it back to its original state

I'm currently working on a feature that toggles an image when a specific class is clicked. The code I have so far successfully switches from 'plus.png' to 'minus.png' upon clicking, but I need it to switch back to 'plus.png&ap ...

Separate line rendering of checkboxes in CSS and Vue

I am struggling with styling Vue checkboxes to display side by side until they wrap to a new line. I have tried modifying the code structure, but the existing CSS classes are causing issues. I have created a simplified example on CodeSandbox. Here is a sn ...

Issue with Live Sass Compiler in Visual Studio Code not creating .css file in designated css folder

In an attempt to organize my project better, I wanted to set the save location of my CSS file to its own folder within the Live Sass Compile Config (Live Sass Compile > Settings:Formats). Initially, I set the savePath to "/css". However, when saving my ...

JavaScript and CSS failing to implement lazy loading with fade-in effect

Is there a way to add the fade-in animation to an image when it is loaded with JavaScript or CSS? Currently, the code I have only fades in the image once it is 25% visible in the viewport. How can I modify it to include the fade effect upon image load? ...

Discover the closest location using geolocation technology

My collection includes various national parks like Alcatraz Island, Death Valley, and Biscayne, each with their respective coordinates. Is there an efficient method to determine the closest park from my database based on the user's current location, ...