Positioning Horizontal Drop Down Menus in CSS

Hello everyone! I am currently working on creating a horizontal dropdown menu. I have created a JS Fiddle to showcase my issue along with an image of the desired outcome.

The problem I am facing is that I cannot get the submenu to align where I want it (on the right side of the container). Additionally, when I set my sub UL to absolute positioning, it does not expand beyond its parent and remains in a vertical orientation. I have only worked on vertical dropdown menus in the past.

    <div id="head">
    <div class="container">
        <a href="#"><strong class="logo pull-left"><h1>CAVO</h1>
        </strong></a> <!-- end logo !-->
        <ul class="nav pull-right">
            <li><a href="#">Menu</a>
                <ul>
                    <li><a href="#">Starters</a></li>
                    <li><a href="#">Breakfast and Brunch</a></li>
                    <li><a href="#">Salads</a></li>
                    <li><a href="#">Sandwiches and Wraps</a></li>
                    <li><a href="#">Pasta</a></li>
                    <li><a href="#">Mains</a></li>
                    <li><a href="#">Pizza</a></li>
                </ul>
            </li>
            <li><a href="#">About Us</a></li>
            <li><a href="#">Contact</a></li>
        </ul>
    </div><!-- end container !-->
</div> <!-- end header !-->

CSS

    body, html {
    height: 5000px;
    font-size: 18px;
    font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
    color: #fff;
    background-color: #222;
}

a {
    text-decoration: none;
    color: inherit;
}

#head {
    height: 76px;
    width: 100%;
    background-color: #472626;
    position: fixed;
    z-index: 10000;
    -webkit-transition: all 300ms ease-out;
    -moz-transition: all 300ms ease-out;
    -ms-transition: all 300ms ease-out;
    -o-transition: all 300ms ease-out;
    transition: all 300ms ease-out;
}

.container {
    max-width: 1400px;
    padding-left: 20px;
    padding-right: 20px;
    margin-left: auto;
    margin-right: auto;
}

.logo {
    line-height: 75px;
    text-align:left;
    -webkit-transition: font-size 2s ease , line-height 0.5s ease;
    -moz-transition: font 0.3s ease , line-height 0.5s ease;
    -o-transition: font 0.3s ease , line-height 0.5s ease;
    -ms-transition: font 0.3s ease , line-height 0.5s ease; 


}

.logo h1 {
    font-size: 2.8em;
    font: "Segoe UI Semibold";
    display:block;
}

.pull-left {
    float: left;
}

.pull-right {
    float:right;    
}

.nav {
    font-size: 1.3em;
    font-family: "wf_SegoeUILight","wf_SegoeUI","Segoe UI Light","Segoe WP Light","Segoe UI","Segoe","Segoe WP","Tahoma","Verdana","Arial","sans-serif";
    font-weight: 100;
}

.nav li {
    float:left;
    padding-left: 15px;
    line-height: 80px;
    -webkit-transition: line-height 0.5s ease;
    -moz-transition: line-height 0.3s ease;
    -o-transition: line-height 0.3s ease;
    -ms-transition: line-height 0.3s ease;
    position: relative;
}

.nav li a {
    opacity: 1;
    -webkit-transition: opacity .2s ease-in-out;
    -moz-transition: opacity .2s ease-in-out;
    -ms-transition: opacity .2s ease-in-out;
    -o-transition: opacity .2s ease-in-out;
    transition: opacity .2s ease-in-out;    
}

.nav li a:hover {
    opacity: .6;    
}

.nav li ul {
    background-color: #2B0909;

}

.nav li ul li a , .nav li ul li{
    display: block;
    float: left;
    line-height:none;
}

Desired result:

Image

Here is the link to my fiddle:

JSFIDDLE

Answer №1

Enhance your current CSS with the following additions:

ul ul{
    position:relative;
    right:-194px;
}
ul li:first-child{
    text-align:right;
}

Check out this live demonstration.

Answer №2

Revise the CSS code in this updated JSFiddle link

.nav li {
    float:right;
    padding-left: 20px;
    line-height: 90px;
    -webkit-transition: line-height 0.8s ease;
    -moz-transition: line-height 0.4s ease;
    -o-transition: line-height 0.4s ease;
    -ms-transition: line-height 0.4s ease;
    width: 105px;
}
.nav li ul {
    background-color: #3D1313;
    position: absolute;
    display: block;
    width: 100%;
    left: 0;

}
.nav li ul li a , .nav li ul li{
    display: inline-block;
    line-height: normal;
    width: 50px;
}

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

Tips for avoiding page postback when using a DevExpress grid in asp.net

On my asp.net page, I have a DevExpress grid that performs sorting and grouping. When a user clicks on sorting or grouping, I need to display a warning message. If the user clicks "OK," the state will be lost, but if they click "Cancel," I need to prevent ...

Establish a constant height while maintaining the original width dimensions

Is there a way to make an image maintain a specific height while also adjusting its width according to the user's screen size? Below is the CSS for the image: #cafe { max-width: 100%; height: 700px; } See the resulting output: https://i.sstatic ...

Retrieve the minimum and maximum values from a multi-dimensional array

If my array consists of the following subarrays: array = [[1, 5, 8, 9], [3, 7], [3, 8, 33], [2], [0, 6]] I am looking to determine the maximum and minimum values in this array. For example, in this case: max = 33, min = 0 While I have come across exampl ...

Show submenu upon hovering and make sure it remains visible

Is there a way to keep a submenu displayed and the background color changed even after moving the mouse away from the menu item onto the submenu? This is my HTML: <div class="shoplink"><a>Online Shop</a></div> <div id="shop-men ...

Leverage the Power of AngularJS to Harness Local

I am currently developing an application using AngularJS. However, I have encountered an issue when trying to use localstorage. Here is my code snippet: var id = response.data[0].id; var email = response.data[0].email; localStorage.setItem('userId&ap ...

The failure of jQuery AJAX error callback to execute

I'm currently facing an issue with an AJAX call that I have in my code. Here's the code snippet: $.ajax({ type: "get", url: "xxx.xxx.xxx/xxx.js", dataType: 'jsonp', success: function(data) { ...

"Is there a way to initiate a Date Picker with the current date using Javascript in an AngularJS application

I am having an issue with my date picker where the month starts from the current month and goes up to the next 12 months. However, I only want to display dates from the current date to the last date of the current month. I believe I need to set a limit so ...

How can one populate the updated information in a repeater without the need to refresh the page or utilize an update panel?

Greetings All, I am wondering if it is possible to update the data from the database on a repeater without having to refresh the page or use an update panel. This is what I need. My requirement involves saving Name and Age to the database: Name <*te ...

Updating the dynamic site script to be compatible with the newest version of the jQuery library

After finding a script on http://css-tricks.com/dynamic-page-replacing-content/, I decided to edit it to suit my needs. Initially, everything worked perfectly with "jquery-1.4.4". However, when I tried using versions later than "jquery-1.5", the active cla ...

Is there a way to retrieve Google Scholar citations using SERPAPI?

I am looking to retrieve citations for a list of authors along with their email IDs. Is there a way to programmatically fetch these citations using SERPAPI? ...

Text in Angular vanishes upon reopening

I have a code snippet where I am trying to allow the user to edit and save a paragraph displayed on a side panel of the main page. Although the code works fine, allowing users to update the text and see it reflected in the network upon saving, there seems ...

Maximizing the width of navbar elements with Bootstrap 3

I am currently working on building a webpage with bootstrap3, but I have encountered an issue with the navigation bar. I would like the navigation links ("Web Design", "Development", "Photography", "Blog") to be evenly spaced out within the horizontal na ...

Entering data into a webpage and retrieving the result from a designated cell in a Google Sheets document

Currently, I am in the process of developing a school platform and I am looking to incorporate a functionality that allows students to easily check the number of "passport" points they have earned. I envision having an input field along with a button that ...

Adjust the angle of an object precisely using a transform upon hovering over a designated button

I am looking to design a menu that always keeps the arrow pointing at the button I hover over with my cursor. If I don't hover on any button, then it should stay in the position of the last button I hovered over. HTML: <html lang="en"> <hea ...

Incorporate pug and sass into your React project for a more

Are pug/jade and sass compatible with react? I enjoy organizing my code by separating files, and the functionality that sass and pug provide is great for this purpose. Is there a way to integrate pug and sass into a react project? Pug example: doctype ...

Having issues with a PHP script that is supposed to generate a webpage

I have been studying web development through the "PHP and MongoDB Web Development" book, where they provide a code snippet for creating a blog post creator. <?php $action = (!empty($_POST['btn_submit']) && ($_POST['btn_submit&apo ...

What could be the reason my HTML5 application is not working offline on my android device?

Hello, I am encountering a problem and I could really use your assistance in figuring out what I am missing. There is a webpage that showcases numerous HTML5 mobile/web applications which can be found at For instance, let's look at this app where yo ...

My custom jQuery for an accordion includes a toggle function. However, when I click on the 2nd tab, the 1st tab should collapse but it is not functioning as expected

I have implemented a Custom jQuery for an Accordion and am using the toggle function. However, when I click on the 2nd tab, the 1st tab is not collapsing as expected.</p> <p>Here is the code Demo for reference</p> Check out the demo her ...

Is there a way to align this button vertically to the bottom of its container with Bootstrap 5?

I'm currently working from this codepen snippet and facing an issue where I can't seem to align the button in the left box to the bottom of the box. Despite trying multiple approaches, I haven't been able to achieve the desired alignment. C ...

Tips for increasing the height of a popover when clicked

When a user focuses on the password input, a popover displays information. At the bottom of the popover, there is a link. How can I make the popover expand when the user clicks on this link? I have tried adding an !important class for the height value, us ...