Two challenges I encountered with my CSS dropdown menu bar

I've been working on a CSS top dropdown navigation bar, but I'm encountering two issues that I can't seem to resolve. The first problem is that my nav div either extends too far down or my 1px right border tabs aren't reaching the bottom properly. The second issue is that my dropdowns are not appearing as they should. You can view the navigation in action on this site: .

Below is the HTML code:

<div id="nav">
<ul>
<li><a href="<?php echo get_option('home'); ?>/">Home</a>
</li>

<li><a href="<?php echo get_option('about us'); ?>/">About Us</a>
<ul>
    <li><a href="<?php echo get_option('home'); ?>/">Why OSTech</a></li>
    <li><a href="<?php echo get_option('home'); ?>/">Testimonials</a></li>
    <li><a href="<?php echo get_option('home'); ?>/">Case Study 1</a></li>
    <li><a href="<?php echo get_option('home'); ?>/">Case Study 2</a></li>
    <li><a href="<?php echo get_option('home'); ?>/">Green IT</a></li>
    <li><a href="<?php echo get_option('home'); ?>/">OSdesk Intel vPro Technology</a></li>
    <li><a href="<?php echo get_option('home'); ?>/">Workstation Innovation</a></li>
    <li><a href="<?php echo get_option('home'); ?>/">Consolidation and Centralisation</a></li>
    <li><a href="<?php echo get_option('home'); ?>/">The Green Grid</a></li>
    <li><a href="<?php echo get_option('home'); ?>/">Clean Technologies</a></li>
    <li><a href="<?php echo get_option('home'); ?>/">OSdesk Remote Management</a></li>
</ul>
</li>
<li><a href="<?php echo get_option('what we do'); ?>/">What We Do</a>
<ul>
    <li><a href="<?php echo get_option('home'); ?>/">OSdesk</a></li>
    <li><a href="<?php echo get_option('home'); ?>/">OSguard</a></li>
    <li><a href="<?php echo get_option('home'); ?>/">OSmon</a></li>
    <li><a href="<?php echo get_option('home'); ?>/">OSvault & OSclass</a></li>
    <li><a href="<?php echo get_option('home'); ?>/">OSmail & OShost</a></li>
    <li><a href="<?php echo get_option('home'); ?>/">OStrack & OSdms</a></li>
    <li><a href="<?php echo get_option('home'); ?>/">OSarchive & OSgroup</a></li>
    <li><a href="<?php echo get_option('home'); ?>/">OSfaq & OShelp</a></li>
    <li><a href="<?php echo get_option('home'); ?>/">OSbill & OScal</a></li>
</ul>
</li>
<li><a href="<?php echo get_option('contact us'); ?>/">Contact Us</a><ul>
</li>
</ul>
</div>

The nav is placed within a floated right div as well. Here is the CSS code. I haven't added the hover effects yet because I want to fix these issues first:

#nav {
   display: block;
   position:relative;
   border: 1px solid #002799;
   background: linear-gradient(to bottom, #4970E3 0%, #121B3E 100%) repeat scroll 0% 0% transparent;
   background: -moz-linear-gradient(to bottom, #4970E3 0%, #121B3E 100%) repeat scroll 0% 0% transparent;
   background: -webkit-linear-gradient(to bottom, #4970E3 0%, #121B3E 100%) repeat scroll 0% 0% transparent;
   padding: 0px 0px 0px 0px;
   border-radius: 15px;
   height: 75px;
   width: 470px;
   margin: 0px auto;
   font: Bold 16px Verdana;
   }

#nav ul {
   margin: 0px;
   padding: 0px;
  }

#nav ul:after {
   content:*.*;
   display:block;
   height: 0px;
   clear:both;
   visibility: hidden;
  }

#nav li {
   list-style: none;
   float: left;
   position: relative;
  }

#nav li a {
    text-decoration: none;
    display: block;
    border-right: 1px solid #121B3E;
    padding: 10px 25px;
   }

#nav ul ul {
    display: none;
    position:absolute;
    left:0px;
    width:0px;
   }

#nav ul ul li {
    border: 1p solid #121B3E;
    width:100%;
   }

#nav ul ul li a {
    border-right: none;
    font: Bold 16px Verdana;
   }

I would greatly appreciate any help or advice on how to solve these problems. Thank you!

Answer №1

Check out the solution provided below:

nav {

display: block; position:relative; border: 1px solid #002799; background: linear-gradient(to bottom, #4970E3 0%, #121B3E 100%) repeat scroll 0% 0% transparent; background: -moz-linear-gradient(to bottom, #4970E3 0%, #121B3E 100%) repeat scroll 0% 0% transparent; background: -webkit-linear-gradient(to bottom, #4970E3 0%, #121B3E 100%) repeat scroll 0% 0% transparent; padding: 0px 0px 0px 0px; border-radius: 15px; height: 40px; width: 470px; margin: 0px auto; font: Bold 16px Verdana; }

nav ul {

margin: 0px; padding: 0px; }

nav ul li {

list-style: none; float: left; position: relative; }

nav ul li:last-child a {

border:none;

}

nav ul li a {

text-decoration: none;
display: block;
border-right: 1px solid #121B3E;
padding: 10px 15px;

}

nav ul ul {

display: none;  
position:absolute;
left:0px;
white-space:nowrap;

}

nav ul li:hover ul {

display:block;

}

nav ul ul li {

border: 1p solid #121B3E;
width:100%;
float:none;
white-space:nowrap;

}

nav ul ul li a {

border-right: none;
font: Bold 16px Verdana;

}

http://jsfiddle.net/nponnen/mM9Z5/

Answer №2

Make sure to take a look at this LabDemo

If you want to display the sub menu, you will need to include the following CSS

#nav ul li:hover ul  {
    display:block; 
    width:100%;
    white-space:nowrap
}

You can find the CSS and HTML by clicking Here

I'll update my response with the codes once you approve it :)

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

Email communication not being successfully transmitted

I've been attempting to add a contact form to my website, but unfortunately, it's not functioning as expected. Following this tutorial, I replaced the $myemail variable with my email address and gave it a try. While I do receive the "thank you" m ...

Issue encountered while presenting canvas on HTML due to Firebase information

Even though I believe I'm following the correct steps, I am facing an issue where the graph displaying real-time database values is not showing up. The first image shows my real-time database and a demostration as shown in images 2 and 3. While the da ...

Ways to center text vertically within a cell in a Bootstrap 5 table

I am trying to achieve vertical alignment in one of the cells of a table I created. According to the Bootstrap 5 documentation, the vertical-alignment utilities only affect certain elements like inline, inline-block, inline-table, and table cell elements. ...

Despite utilizing the .img-fluid class, the image remains incompatible with the parent div and does not fit properly

So, I'm currently working on a test code where my aim is to fit an image into the parent div using Bootstrap 5. However, I'm facing a challenge where the image leaves a noticeable gap width-wise, despite using the .img-fluid class. You can see th ...

Conceal one object when the other is revealed?

Is there a way to hide the element with the class .close-button while showing another element with the ID #loading-animation? Can jQuery conditionals help achieve this? For example: if ($('#loading-animation').is(':visible')) { $ ...

Building an array of ids that contain the checkbox type using jQuery: What's the best way?

Below is the HTML snippet I am working with: <!-- Parent checkbox code goes here --> <input id="ckbCheckAll" class="custom-check ez-hide" type="checkbox" name=""></input> <!-- Child checkbox codes follow --> <input id="practice_ ...

Is it possible to incorporate vector graphics/icons by simply adding a class to a span element in HTML5?

In order to add a glyphicon icon to our webpage, we simply need to include its class within a span element, as demonstrated here: <span class="glyphicon glyphicon-search"></span> We also have a few files in .ai format that can be converted to ...

What is causing the bullets for the unordered list to appear before the items are inserted into the list?

Can you explain why the bullets are showing up before the list items are added? <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>To Do List</title> </head> <body> ...

Cordova Geolocation now displaying incorrect latitude and longitude values as NAN

Recently starting out with javascript and Cordova, I decided to develop a basic GPS app in Visual Studio 2015. The goal was simple: get my current position by clicking on the "CURRENT POSITION" button. Testing it in Firefox yielded positive results. Howev ...

does not output any console log statements

I am attempting to showcase the values of checkboxes on the console, however, it is not working. <input type="checkbox" id="id_price" value="1" onclick="display_img()">Under £200<br> <input type="checkbox" id="id_pr ...

Issues arise when implementing ReactJS transitions for progress bars

As a newcomer to the world of ReactJS, I have been exploring the FB documentations and online tutorials to kickstart my test project. Within this project, I wanted to implement a progress bar that visually represents the user's progression through fi ...

Navigating to a precise location on initial page load using Angular 11

Within the structure of my app, I have a parent component that displays a large image from a child component. When the parent component loads, I want the browser window to automatically scroll to a specific position in order to center the image. Currently ...

Tips for managing mouseover events on a row within an HTML table

My HTML code includes a table like the following: <table> <tr class="myClass"> <td>John</td> <td>Smith</td> </tr> </table> I am trying to change the font color, background color, and use a poi ...

Generate time-dependent animations using circles

Hey there, I am trying to create an animation that involves drawing three circles and having one of them move from right to left. The circles should appear randomly in yellow, blue, or orange colors on the canvas at different intervals (3 seconds between ...

Focused on individual characters in a string to implement diverse CSS styles

Is there a way I can apply different CSS classes to specific indexes within a string? For example, consider this string: "Tip. \n Please search using a third character. \n Or use a wildcard." I know how to target the first line with CSS using : ...

How to Incorporate LessCSS into the Blueprint Framework?

Can LessCSS be integrated with Blueprint framework? What are the prerequisites for starting? ...

Triggering a modal window with unique content by clicking on various images

Is there a way to trigger a modal window through clicking on an image? Additionally, can different images open different content upon clicking? I am planning to showcase a portfolio where clicking on an image will activate a modal that displays other image ...

Discover the secret to extracting a unique style from inspect mode and incorporating it into your CSS design

I'm currently working on my angular project and I've imported the ngx-editor. My goal is to reduce the height of the editor, but I'm facing some challenges. After inspecting the element, I was able to adjust the height successfully within th ...

Having trouble updating the icon on my website using FontAwsome

Just a heads up - I'm not familiar with HTML/CSS/JS. This template is pre-made, and I'm simply making some adjustments to it. Hello, I'm currently working on my portfolio website and I want to display my projects based on the programming la ...

Ellipsis not displaying correctly in a paragraph class with text overflow issue

I'm currently tackling a project that prioritizes mobile-first design. While I have a list of elements to work with, I've encountered an issue with one in particular. In this project, I want the "h3" element to always be fully visible for easy re ...