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

Is it possible for Javascript to manipulate the DOM of an Ajax text/html response?

My goal is to implement Ajax to retrieve an HTML page and extract a specific div by its ID, then insert that div into the current page. This involves loading a second page via Ajax, extracting the specified div from the response, and placing it within th ...

Tips on customizing styles for Material UI components using CSS override techniques

Currently, I am tackling a project that requires the use of Material UI components. To simplify things, let's focus on a basic functional component that includes two Material UI elements: a Button and a Text Field. import React from 'react'; ...

Creating a competition schedule - pieces don't quite mesh

Having trouble getting my tournament bracket visuals to come together smoothly! Here is the CSS code I have: #tournament-holder{ width:708px; padding:20px 0 20px 15px; float:left; } .vertical-holder{ width:100px; padding-right:15px; float:left; } .horizo ...

Error encountered while rendering HTML template with Django and AngularJS due to TemplateSyntaxError

Hello, I am new to Angular and Django. I have built a Django webpage and am attempting to display values from a basic AngularJS app and controller tutorial using my HTML template. However, I keep encountering an error in the index.html file when trying to ...

Issue with border in a nested table within an HTML table

I am faced with an issue in styling nested tables. My goal is to have borders on both tables, but I specifically need only the bottom border of the inner table without the top, right, and left borders. The default border style can be achieved using the fol ...

Using Express.js to render an HTML table in a web page

Is there a way to display a full table using the res.render method? This is what I'm attempting to do: I need to define where to send one of my tables. main.hbs <html> ... <div id="main_frame" class="col s12">{{{bod ...

The text field is being styled with inline styles automatically

I am trying to set a custom width for a textarea in my form, but the inline styles are automatically overriding my CSS. I have checked my scripts, but I am unsure which one is manipulating the DOM. If you have any insight, please let me know. This is the ...

The asynchronous ajax request is leading to a browser freeze

In the HTML page, I have two sets of a and p elements that are initially set to display:none. At the bottom of the page, there is a function being called with their respective ID's and values, which will enable one of them based on certain conditions ...

Is it possible to change a Material UI style without resorting to an HOC?

Is there any method to modify the styling of a Material UI component without the need to create an entirely new component using withStyles()? For example, if I am currently displaying the following and simply want to adjust the color of the "Delete" label ...

Tips for avoiding a large <ul> element from spilling over the body in a flexbox design

I struggled to articulate the problem I am facing, and I apologize if it's still unclear So, in my app, I have 3 cards, and the 2 side ones contain lists (<ul>) that can become quite lengthy. I want the scrollbar to appear on the <ul> its ...

How can I make CSS images appear beside specific links?

Currently, I have implemented the following CSS: .entry a { padding: 2px 0 0 8px; background: transparent url(images/link_arrow_light.gif) left top no-repeat; text-decoration: underline; } It is functioning correctly, but the image is being added t ...

The action to set the 'isRightSidebarExpanded' property is trying to target an undefined element

I'm currently in the process of adapting a template for use with nuxt.js This specific attribute is causing an error to occur When trying to set 'isRightSidebarExpanded', I receive the following error: Cannot set properties of undefined ...

Local cross-origin requestsORCross-origin requests within local

I'm having an issue with a simple setup that I can't seem to figure out: This is my index.html file: <!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>SyriLab</title> <link rel="stylesheet" ...

What is the process to set a Woocommerce checkout field as optional when a checkbox is marked?

I need assistance with customizing the checkout page on Wordpress Woocommerce. Specifically, I want to make the field 'billing_name' not required if the checkbox 'buy_on_company' is checked. Currently, I have successfully hidden ' ...

Error encountered when assigning a value to a session array in PHP 7.0

I am the author of this script <?php session_start(); if($_POST["num"] > $_SESSION["ratings"][$_POST["title"]]) $SESSION["ratings"][$_POST["title"]] = $_POST["num"]; ?> Although my syntax seems correct to me, the IDE is showin ...

Tumblr post not automatically playing flash content

I am facing an issue with embedding a flash object on my tumblr blog (Billy's audio player) where I have to click a white play button for the object to work properly. This problem seems to occur specifically in Chrome and Edge browsers, as other websi ...

Click on the navigation bar buttons to toggle between different divs and display multiple information boxes simultaneously

Here is the current code snippet... $("#contact").click(function() { if ( $( "#contact_div" ).length ) { $("#contact_div").remove(); } else { var html='<div id="contact_div" class="contact-info"><p>Contact info</p&g ...

What is the best way to duplicate a complete row?

I am looking to create a form that includes an "Add Row" button. When this button is clicked, a new row should be generated, identical to the last row. The rows contain dropdown values, and I want the new row to display the same dropdown options as the p ...

Ways to deactivate webfonts specifically for Safari

Recently, I have been experiencing font crashing issues with the webfont on Safari. Is there a way to disable this font specifically for this browser? ...

Unable to reset the HTML5 slider successfully

Despite multiple attempts, I have finally reached out for assistance. Here is the code snippet for my slider: <input autocomplete="off" type="range" min="0" max="100" value="50" class="myslider" id="mysliderID-slider" data-fieldid="something"> <i ...