Looking to expand the width of the sub menu to reach the full width of the

Is there a way to use CSS to make a sub-menu start from the left side of the screen instead of starting it below the parent item?

nav {
     margin: 0 auto;
     text-align: center;
}
 nav ul ul {
     display: none;
}
 nav ul li:hover > ul {
     display: block;
}
 nav ul {
     list-style: none;
}
 nav ul li {
     float: left;
}
 nav ul li:hover a {
     color: #000000;
     margin-bottom:5px;
     border-top: 1px solid #000000;
     border-bottom: 1px solid #000000;
}
 nav ul li a {
     display: block;
     padding: 5px 15px;
     color: #000000;
     text-decoration: none;
}
 nav ul ul {
     border-radius: 0px;
     padding: 0;
     position: absolute;
}
 nav ul ul li {
     float: none;
     position: relative;
}
 nav ul ul li a {
     color: #000000;
}
 nav ul ul li a:hover {
     color: #666666;
}
 nav ul ul ul {
     position: absolute;
     top:0;
}
<nav>
   <ul>
      <li>
         <a href="/view_contacts.php">Contacts</a>
         <ul>
            <li><a href="add_contact.php">Add Contact</a></li>
            <li><a href="view_contacts.php">View Contacts</a></li>
         </ul>
      </li>
      <li>
         <a href="/tickets.php">Tickets</a>
         <ul>
            <li><a href="new_ticket.php">New Ticket</a></li>
            <li><a href="tickets.php">View Tickets</a></li>
         </ul>
      </li>
      <li><a href="/invoices.php">Invoices</a></li>
      <li><a href="/itemised_calls.php">Itemised Calls</a></li>
   </ul>
</nav>

Here is a jsfiddle link for demonstration, hope it helps! : http://jsfiddle.net/jhmkqrye/1/

Currently, the sub-menu for "Tickets" starts from below the ticket, but I want it to begin below "Contacts" from the start of the screen width to the end of the screen width.

Answer №1

To achieve the desired effect, consider setting the parent element's position to relative and the child elements' to absolute. Then you can specify the positioning using left, right, bottom, top.

As an illustration, setting left: 0; would position your child item all the way to the left.

Update: Is there a potential issue with the jsfiddle link? I couldn't locate any sub-menu upon hovering, and when clicked, it leads to a 404 error page.

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

The concept of global object/scope and circular references in undefined cases

Trying to make sense of the outcomes from these few experiments : Experiment number 1 (in a new command line) : > _ ReferenceError: _ is not defined at repl:1:2 at REPLServer.self.eval (repl.js:110:21) at Interface.<anonymous> (repl. ...

Is there a way to prevent the text in my text boxes from staying there when I refresh the page?

Currently working on an HTML5 project with Javascript, here is a snippet of my code: Your inquiry <textarea type="text" name="phrase" id="phrase" cols="50" rows="5" placeholder="Write your text here. . ."></textarea> I am looking for a way ...

Tips for replacing all occurrences of a specific string in HTML while preserving JavaScript attributes

Is there a way to use RegEx to replace part of an HTML document without affecting the root element or other elements like event listeners? Consider this scenario: for (; document.body.innerHTML.indexOf(/ea/) != -1;) { document.body.innerHTML = docu ...

Best Practices for Variable Initialization in Stencil.js

Having just started working with Stencil, I find myself curious about the best practice for initializing variables. In my assessment, there seem to be three potential approaches: 1) @State() private page: Boolean = true; 2) constructor() { this.p ...

Invalid label detected - Syntax Error in the response from Jsonp/Ajax!

I have a snippet of code that I'm having trouble with. It's shown below: <script type="text/javascript"src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script> <script type="text/javascript"> jQuery.getJSO ...

Retrieving Information from an Angular 2 Component

Struggling to figure this out, I am attempting to dynamically add user video data that includes a video URL. My goal is to access the data from the component so I can use it in my HTML. I've attempted the following approach. app.component.ts import ...

The problem with asynchronous requests in Ajax

In the code below, I have noticed that when an alert() box is used and then clicked, the content loads on the page. However, without the alert() box, the content does not load. I've tried researching 'Ajax' requests extensively but still can ...

Using AngularJS to connect a directive with a controller function

After updating my records, I am looking to trigger a controller function from a directive. Below is the code snippet being used: Controller.js app.controller('GetAlphabetical', function ($scope, $http) { function getCutomers() { ...

Overlapping Image Arrows with CSS Styling

After receiving a design with what appeared to be a simple feature from a designer, I discovered that implementing it was more complex than expected. Specifically, I needed to create a CSS3 arrow with an image as the fill color in order to overlap the unde ...

What could be causing the malfunction of my navbar and carousel functionality?

I am currently facing some challenges with the carousel in my HTML code. I am unable to get it to display images properly. Additionally, there is an issue with the background color of my navigation bar - it doesn't stay at 100% width. Also, when using ...

Can the data retrieved from a jsonp call that may be considered "bad" be utilized effectively?

When making a JSONP call to another domain, I am receiving data that is in JSON format but not wrapped in a function. This causes a parse error to occur. However, the data is still retrievable and visible. Despite the error, is it possible to utilize the ...

"Adjusting the height of Material UI card content to ensure fixed positioning at the bottom

Currently, I am working on mapping material-ui cards with dynamic content from a JSON object, resulting in varying card heights. I have successfully set a fixed height for each card, but the content is not aligned correctly. You can see the issue in this ...

What is the appropriate way to utilize `render_template` from Flask within Angular?

I'm facing an issue where I need to implement different routes for various Angular Material tabs. I have attempted to directly call Flask from the template, as demonstrated below, but unfortunately, I am unable to invoke render_template from Angular. ...

Tips for obtaining unique identifiers in a "foreach" data binding to create a sortable accordion

Hey there! I'm looking to implement a sortable accordion (http://jqueryui.com/accordion/#sortable) in conjunction with the knockout-js "data-bind: foreach" loop. Each iteration of my loop will require a unique "id", but I'm unsure how to dynamic ...

"Utilizing JSON parsing in Node.js and rendering the data in a Jade template

I need assistance with parsing JSON and presenting the response in a tabular format using Jade. Can you help me display the key-value pairs in two separate columns? Node.js exports.postMQinput = function(req, res) { req.assert('name', 'Q ...

Altering the text of dropdown items prior to the ASP.NET autopostback

Recently, I inherited a project from a client that is plagued with some irritating issues. One particular problem involves a dropdown menu that triggers an autopostback event upon selection change, inserting the selected text into a T-SQL query. The troubl ...

How to detect and resolve the problem of an empty div tag

I'm trying to determine if a div is empty and add the text "empty" to it if it is. Can anyone help me figure out what I'm doing wrong? Thank you in advance! View my jsFiddle file HTML <div class="staff-row"> <img alt="" src="foo.j ...

Is it possible to use both interfaces and string union types in TypeScript?

My goal is to create a method that accepts a key argument which can be either a string or an instance of the indexable type interface IValidationContextIndex. Here is the implementation: /** * Retrieves all values in the ValidationContext container. ...

werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The server is unable to process the request sent by the browser or proxy. This error occurred in a Flask web application

Can someone guide me on troubleshooting this issue in Flask? I am still learning. Server running at (Press CTRL+C to exit) 127.0.0.1 - - [26/Jul/2020 11:19:45] "GET /predict HTTP/1.1" 500 - Traceback (most recent call last): raise exceptions. ...

Is it acceptable to include a checkbox and a hidden input within a label element?

When creating a list of possible products for users to buy, I use the ul tag combined with li. Each product element includes a checkbox that allows users to select the product or not. For products with related information, I want to store this data in a h ...