aligning sub menu with the main menu - html

My sub-menu and sub-sub-menu seem to have a lot of gap from each other and is not aligned with the main menu. I want the sub-menu to drop down straight from the main menu and sub-sub-menu to open up on the right side of the sub-menu when hovered over. How can I do that?
below are my codes:
.nav-bar {
max-height: 0;
margin-left: 0;
padding-left:20px;
padding-top: 200px;
}
.box-nav-bar ul{
display:inline-block;
text-decoration: none;
padding: 0;
list-style-type: none;
margin:0;
}
.box-nav-bar ul li{
display: inline-block;
padding: 20px;
border: 1px solid grey;
width: 100px;
height: 50px;
line-height: 50px;
text-align: center;
position: relative;
}
.box-nav-bar ul li a{
text-decoration: none;
list-style: none;
color: black;
font-size: 18px;
font-weight: bold;
font-family: Arial;
display:block;
}
.box-nav-bar ul li:hover{
background-color: grey;
}
.box-nav-bar ul .sub-menu ul li{
text-decoration: none;
padding: 0;
margin: 0;
list-style-type: none;
width: 150px;
}
.box-nav-bar ul .sub-menu {
display: none;
font-size: 14px solid;
position:absolute;
text-align: center;
}
.box-nav-bar li:hover .sub-menu{
display: block;
}
.sub-sub-menu{
display: none;
font-size: 14px solid;
position:absolute;
text-align: center;
}
.box-nav-bar li:hover .sub-menu li:hover{
display: block;
}
<div class="nav-bar">
<nav class="box-nav-bar">
<ul>
<li> HOME</li>
<li> ABOUT</li>
<li> SERVICES
<ul class="sub-menu">
<li>
Lorem ipsum
</li>
<li>
Dolor sit amet
</li>
<li>
Conse ctetur
<ul class="sub-sub-menu">
<li>
Latest
</li>
<li>
Archive
</li>
</ul>
</li>
</ul>
</li>
<li> PROJECTS</li>
<li> CONTACTS</li>
</ul>
</nav>
</div>
Thank you.

You have position: absolute on your .sub-menu and .sub-sub-menu. You just have to align your container blocks using the top and left properties.
Also font-size: 14px solid is invalid as solid is a border-type attribute and not required with font-size. Change it simply to font-size: 14px.
Refer code:
.nav-bar {
max-height: 0;
margin-left: 0;
padding-left: 20px;
padding-top: 200px;
}
.box-nav-bar ul {
display: inline-block;
text-decoration: none;
padding: 0;
list-style-type: none;
margin: 0;
}
.box-nav-bar ul li {
display: inline-block;
padding: 20px;
border: 1px solid grey;
width: 100px;
height: 50px;
line-height: 50px;
text-align: center;
position: relative;
}
.box-nav-bar ul li a {
text-decoration: none;
list-style: none;
color: black;
font-size: 18px;
font-weight: bold;
font-family: Arial;
display: block;
}
.box-nav-bar ul li:hover {
background-color: grey;
}
.box-nav-bar ul .sub-menu ul li {
text-decoration: none;
padding: 0;
margin: 0;
list-style-type: none;
width: 150px;
}
.box-nav-bar ul .sub-menu {
display: none;
font-size: 14px;
position: absolute;
text-align: center;
top: 91px;
left: 0;
}
.box-nav-bar li:hover .sub-menu {
display: block;
}
.sub-sub-menu {
display: none;
font-size: 14px;
position: absolute;
text-align: center;
top: 0px;
left: 140px;
}
.box-nav-bar li:hover .sub-menu li:hover {
display: block;
}
<div class="nav-bar">
<nav class="box-nav-bar">
<ul>
<li> HOME</li>
<li> ABOUT</li>
<li> SERVICES
<ul class="sub-menu">
<li>
Lorem
</li>
<li>
Dolor
</li>
<li>
Conse
<ul class="sub-sub-menu">
<li>
Latest
</li>
<li>
Archive
</li>
</ul>
</li>
</ul>
</li>
<li> PROJECTS</li>
<li> CONTACTS</li>
</ul>
</nav>
</div>

This will help you get started.
.nav-bar {
max-height: 0;
margin-left: 0;
padding-left: 20px;
padding-top: 200px;
}
.box-nav-bar ul {
display: inline-block;
text-decoration: none;
padding: 0;
list-style-type: none;
margin: 0;
}
.box-nav-bar ul li {
display: inline-block;
padding: 20px;
border: 1px solid grey;
width: 100px;
height: 50px;
line-height: 50px;
text-align: center;
position: relative;
}
.box-nav-bar ul li a {
text-decoration: none;
list-style: none;
color: black;
font-size: 18px;
font-weight: bold;
font-family: Arial;
display: block;
}
.box-nav-bar ul li:hover {
background-color: grey;
}
.box-nav-bar ul .sub-menu ul li {
text-decoration: none;
padding: 0;
margin: 0;
list-style-type: none;
width: 150px;
}
.box-nav-bar ul .sub-menu {
display: none;
font-size: 14px solid;
position: absolute;
text-align: center;
left: 0;
top: 100%;
}
.box-nav-bar li:hover .sub-menu {
display: block;
}
.sub-menu li {
width: 100% !Important;
}
.sub-menu li:hover .sub-sub-menu {
display: block !important;
}
.sub-sub-menu {
display: none !important;
font-size: 14px solid;
position: absolute;
text-align: center;
top: -2px;
left: 100%;
}
.box-nav-bar li:hover .sub-menu li:hover {
display: block;
}
.sub-sub-menu li {
width: 100% !important;
display: block !important;
padding: 20px !important;
}
<div class="nav-bar">
<nav class="box-nav-bar">
<ul>
<li> HOME</li>
<li> ABOUT</li>
<li> SERVICES
<ul class="sub-menu">
<li>
Lorem ipsum
</li>
<li>
Dolor sit amet
</li>
<li>
Conse ctetur
<ul class="sub-sub-menu">
<li>
Latest
</li>
<li>
Archive
</li>
</ul>
</li>
</ul>
</li>
<li> PROJECTS</li>
<li> CONTACTS</li>
</ul>
</nav>
</div>

Related

The submenu doesn't show up when hover the mouse

I have a problem. I don't know what wrong with the code as when I hover the mouse over 'About us', the submenu didn't show up. I did make the submenu display:none and then when hover, it display: block but nothing happen. Thanks for your help
#nav_menu{
list-style: none;
margin: 0;
padding: 0;
position: relative;
}
#nav_menu li{
float: left;
}
#nav_menu li a{
display: block;
width: 160px;
padding-top: 1em;
padding-bottom: 1em;
text-decoration: none;
background-color: #800000;
color: white;
font-weight: bold;
text-align: center;
}
#nav_menu .current{
color: yellow;
}
#nav_menu #sub_menu{
display: none;
position: absolute;
top: 100%;
list-style: none;
}
#nav_menu #sub_menu:hover{
display: block;
}
#nav_menu #sub_menu li a{
float: right;
}
<ul id="nav_menu">
<li>Home</li>
<li>Speakers</li>
<li>Luncheons</li>
<li>Tickets</li>
<li>About Us
<ul id="sub_menu">
<li>Our History</li>
<li>Board of Directors</li>
<li>Past Speakers</li>
<li>Contact Information</li>
</ul>
</li>
</ul>
My method is a little different and shorter with the animation opening and closing for the submenu, I used the scale instead of display for animation;
body {
box-sizing: border-box;
margin: 0;
padding: 0;
}
#nav_menu{
list-style: none;
margin: 0;
padding: 0;
position: relative;
}
#nav_menu li{
float: left;
position: relative;
}
#nav_menu li a{
display: block;
width: 160px;
padding-top: 1em;
padding-bottom: 1em;
text-decoration: none;
background-color: #800000;
color: white;
font-weight: bold;
text-align: center;
}
#nav_menu .current{
color: yellow;
}
#nav_menu #sub_menu{
position: absolute;
top: 100%;
list-style: none;
padding: 0;
transform : scaleY(0);
transform-origin: top;
transition: all 0.4s;
}
#nav_menu li:hover #sub_menu{
transform: scaleY(1);
}
#nav_menu #sub_menu li a{
float: right;
}
<ul id="nav_menu">
<li>Home</li>
<li>Speakers</li>
<li>Luncheons</li>
<li>Tickets</li>
<li>About Us
<ul id="sub_menu">
<li>Our History</li>
<li>Board of Directors</li>
<li>Past Speakers</li>
<li>Contact Information</li>
</ul>
</li>
</ul>
To display a submenu when hovering, you need to write like this:
#nav_menu li:hover #sub_menu {
display: block;
}
Because you are accessing the #sub_menu selector. Also, you need to add position: relative the selector #nav_menu li is relevant for the correctness of your position: absolute of the selector #nav_menu #sub_menu. And add padding: 0 for the selector of the same selector #nav_menu #sub_menu, in order to align it under the main menu.
body {
box-sizing: border-box;
margin: 0;
padding: 0;
}
#nav_menu{
list-style: none;
margin: 0;
padding: 0;
position: relative;
}
#nav_menu li{
float: left;
position: relative;
}
#nav_menu li a{
display: block;
width: 160px;
padding-top: 1em;
padding-bottom: 1em;
text-decoration: none;
background-color: #800000;
color: white;
font-weight: bold;
text-align: center;
}
#nav_menu .current{
color: yellow;
}
#nav_menu #sub_menu{
display: none;
position: absolute;
top: 100%;
list-style: none;
padding: 0;
}
/*#nav_menu #sub_menu:hover{
display: block;
}*/
#nav_menu li:hover #sub_menu{
display: block;
}
#nav_menu #sub_menu li a{
float: right;
}
<ul id="nav_menu">
<li>Home</li>
<li>Speakers</li>
<li>Luncheons</li>
<li>Tickets</li>
<li>About Us
<ul id="sub_menu">
<li>Our History</li>
<li>Board of Directors</li>
<li>Past Speakers</li>
<li>Contact Information</li>
</ul>
</li>
</ul>

Displaying a sub-sub-menu on hover of menu with CSS

I need to display sub-sub-menu on hover of my sub-menu. So far I did code to display menu -> sub-menu on menu click, but to proceed I want a functionality to display sub-sub-menu on hover of my sub-menu. Can somebody help me to achieve the same?
var ddmenuitem = 0;
function jsddm_open() {
jsddm_close();
ddmenuitem = $(this).find('ul.submenu').css('display', 'block');
// $(this).find('div.subsubmenu').css('display','none');
}
function jsddm_close() {
if (ddmenuitem) ddmenuitem.css('display', 'none');
}
$(document).ready(function() {
$('#topnav > ul > li').bind('click', jsddm_open)
$('#topnav > ul > li > a').click(function(ev) {
if ($(this).hasClass('current')) {
ev.preventDefault();
}
if ($(this).attr('class') != 'active') {
$('#topnav ul li a').removeClass('active');
$(this).addClass('active');
}
});
});
#topnav {
float: left;
width: 600px;
height: 30px;
background: black;
margin-top: 10px;
position: relative;
font-size: 15px;
margin-left: 30px
}
#topnav ul {
list-style: none;
padding: 0px;
margin: 0px;
}
#topnav ul li {
float: left;
margin: 0;
padding: 0;
}
#topnav ul li a {
padding: 5px 15px;
color: red;
text-decoration: none;
display: block;
font-weight: bold;
}
#topnav ul li a:link {
color: red;
text-decoration: none;
}
#topnav ul li a:visited {
color: #FFF;
text-decoration: none;
}
#topnav ul li a:hover {
color: red;
text-decoration: none;
}
#topnav ul li a.active {
text-decoration: none;
color: black;
background: #e0e0e0;
}
#topnav ul li ul.submenu {
float: left;
padding: 4px 0;
position: absolute;
left: 0;
top: 30px;
display: none;
background: #e0e0e0;
color: #00537F;
width: 600px;
height: 30px;
}
#topnav ul li ul.submenu a {
display: inline;
color: #00537F;
padding: 4px 8px;
}
#topnav ul.submenu a:hover {
background-color: black;
color: white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="topnav">
<ul>sds
<li>
Admin
</li>
<li>
MAC
<ul class="submenu">
<li>Master Data</li>
<li>
Transaction Data
<ul>
<li>Company Master</li>
<li>Location Master</li>
<li>Size Master</li>
</ul>
</li>
<li>
Admin Data
</li>
</ul>
</li>
</ul>
</div>
Try the following snippet without using jquery or javascript, you can get it done using only css. And have updated according to your question
#nav {
list-style: none inside;
margin: 0;
padding: 0;
text-align: center;
}
#nav li {
display: block;
position: relative;
float: left;
background: #000000;
}
#nav li a {
display: block;
padding: 0;
text-decoration: none;
width: 200px;
line-height: 35px;
color: #fff;
}
#nav li li a {
font-size: 80%;
}
#nav li:hover {
background: #ff0000;
}
#nav ul {
position: absolute;
padding: 0;
left: 0;
display: none;
}
#nav li:hover ul ul {
display: none;
}
#nav li:hover ul {
display: block;
}
#nav li li:hover ul {
display: block;
margin-left: 200px;
margin-top: -35px;
}
<div id="topnav">
<ul id="nav">
<li>
Admin
</li>
<li>
MAC
<ul class="submenu">
<li>Master Data</li>
<li>
Transaction Data ⇒
<ul>
<li>Company Master</li>
<li>Location Master</li>
<li>Size Master</li>
</ul>
</li>
<li>
Admin Data
</li>
</ul>
</li>
</ul>
</div>
you can try this
#menu {
background: #343434;
color: #eee;
height: 35px;
border-bottom: 4px solid #eeeded
}
#menu ul,
#menu li {
margin: 0 0;
padding: 0 0;
list-style: none
}
#menu ul {
height: 35px
}
#menu li {
float: left;
display: inline;
position: relative;
font: bold 12px Arial;
text-shadow: 0 -1px 0 #000;
border-right: 1px solid #444;
border-left: 1px solid #111;
text-transform: uppercase
}
#menu li:first-child {
border-left: none
}
#menu a {
display: block;
line-height: 35px;
padding: 0 14px;
text-decoration: none;
color: #eee;
}
#menu li:hover > a,
#menu li a:hover {
background: #111
}
#menu input {
display: none;
margin: 0 0;
padding: 0 0;
width: 80px;
height: 35px;
opacity: 0;
cursor: pointer
}
#menu label {
font: bold 30px Arial;
display: none;
width: 35px;
height: 36px;
line-height: 36px;
text-align: center
}
#menu label span {
font-size: 12px;
position: absolute;
left: 35px
}
#menu ul.menus {
height: auto;
width: 180px;
background: #111;
position: absolute;
z-index: 99;
display: none;
border: 0;
}
#menu ul.menus li {
display: block;
width: 100%;
font: 12px Arial;
text-transform: none;
}
#menu li:hover ul.menus {
display: block
}
#menu a.home {
background: #c00;
}
#menu a.prett {
padding: 0 27px 0 14px
}
#menu a.prett::after {
content: "";
width: 0;
height: 0;
border-width: 6px 5px;
border-style: solid;
border-color: #eee transparent transparent transparent;
position: absolute;
top: 15px;
right: 9px
}
#menu ul.menus a:hover {
background: #333;
}
#menu ul.menus .submenu {
display: none;
position: absolute;
left: 180px;
background: #111;
top: 0;
width: 180px;
}
#menu ul.menus .submenu li {
background: #111;
}
#menu ul.menus .has-submenu:hover .submenu {
display: block;
}
<nav>
<ul id='menu'>
<li><a class='home' href='/'>Home</a></li>
<li><a class='prett' href='#' title='Menu'>Menu</a>
<ul class='menus'>
<li class='has-submenu'><a class='prett' href='Dropdown 1' title='Dropdown 1'>Dropdown 1 + Sub Menu</a>
<ul class='submenu'>
<li>Sub Menu</li>
<li>Sub Menu 2</li>
<li>Sub Menu 3</li>
</ul>
</li>
<li><a href='#' title='Dropdown 2'>Dropdown 2</a></li>
<li><a href='#' title='Dropdown 3'>Dropdown 3</a></li>
</ul>
</li>
</ul>
</nav>

Content move down when I apply float property

I have to float the class time to right but when I try to float it right, its content moves down. Without float contents look fine but I have to float it.
https://jsfiddle.net/jyckLwv7/
.main-nav {
color: #FFF;
width: 100%;
background-color: #5e2d91;
float: right;
line-height: 42px;
margin-top: -3px;
}
.main-nav ul li {
display: inline;
padding: 0px 10px;
}
.main-nav ul li a {
color: #FFF;
text-decoration: none;
padding: 20px 14px;
}
.main-nav ul {
margin-bottom: 7px !important;
}
.main-nav ul li a:hover {
background-color: #0098aa;
}
.main-nav ul li a:active {
background-color: #6A006A;
}
.time {
float: righ;
background: #5e2d91;
color: #FFFFFF;
border-color: #718b88;
font-family: sans-serif;
font-weight: bold;
border-style: solid;
margin-left: 10%;
width: 228px;
height: 33px;
margin-top: 9px;
float: right;
}
<nav class="main-nav">
<ul>
<li> Home
</li>
<li> Trade Now
</li>
<li> Transactions
</li>
<li> Performance
</li>
<li>History
</li>
<li class="time">US Markets Open in <span id="hm_timer" class="style colorDefinition size_sm">08:20:04</span>
</li>
</ul>
</nav>
First of all, don't use margin-top: -3px to fight off that default padding browsers set to body, as this padding varies from browser to browser. To achieve a more consistent visual output, you can try normalising this properties with something like:
html, body {
margin: 0;
padding: 0;
}
Now, coming to your alignment issue, try removing height and width from .time and vertical-align: middle to your li elements.
jsFiddle: → here
Code: (expand the snippet)
html, body {
margin: 0;
padding: 0;
}
.main-nav, .main-nav ul li {
display: inline-block;
}
.main-nav {
color: #FFF;
width: 100%;
background-color: #5e2d91;
line-height: 24px;
}
.main-nav ul li {
padding: 0px 10px;
vertical-align: middle;
}
.main-nav ul li a {
color: #FFF;
text-decoration: none;
padding: 20px 14px;
}
.main-nav ul li a:hover {
background-color: #0098aa;
}
.main-nav ul li a:active {
background-color: #6A006A;
}
.time {
float: right;
border-color: #718b88;
font-family: sans-serif;
font-weight: bold;
border-style: solid;
margin-left: 10%;
}
<nav class="main-nav">
<ul>
<li>Home</li>
<li>Trade Now</li>
<li>Transactions</li>
<li>Performance</li>
<li>History</li>
<li class="time">US Markets Open in
<span id="hm_timer"class="style colorDefinition size_sm">08:20:04</span>
</li>
</ul>
</nav>
Add overflow: hidden to the ul element:
.main-nav ul {
margin-bottom: 7px !important;
overflow: hidden;
}
.main-nav {
color: #FFF;
width: 100%;
background-color: #5e2d91;
float: right;
line-height: 42px;
margin-top: -3px;
}
.main-nav ul li {
display: inline;
padding: 0px 10px;
}
.main-nav ul li a {
color: #FFF;
text-decoration: none;
padding: 20px 14px;
}
.main-nav ul {
margin-bottom: 7px !important;
overflow: hidden;
}
.main-nav ul li a:hover {
background-color: #0098aa;
}
.main-nav ul li a:active {
background-color: #6A006A;
}
.time {
background: #5e2d91;
color: #FFFFFF;
border-color: #718b88;
font-family: sans-serif;
font-weight: bold;
border-style: solid;
margin-left: 10%;
width: 228px;
height: 33px;
margin-top: 9px;
float: right;
}
<nav class="main-nav">
<ul>
<li> Home
</li>
<li> Trade Now
</li>
<li> Transactions
</li>
<li> Performance
</li>
<li>History
</li>
<li class="time">US Markets Open in <span id="hm_timer" class="style colorDefinition size_sm">08:20:04</span>
</li>
</ul>
</nav>
When using floating container, always remember to clear the floats- see this answer for more information.
Note that while using floating containers, you should always clear
them before the next container that follows thereby creating a fresh
block formatting context as it is called. Otherwise you will see
unpredictable behavior.
Instead of overflow: hidden you can also clear the float by using:
.main-nav ul:after {
content: '';
display: block;
clear: both;
}
.main-nav {
color: #FFF;
width: 100%;
background-color: #5e2d91;
float: right;
line-height: 42px;
margin-top: -3px;
}
.main-nav ul li {
display: inline;
padding: 0px 10px;
}
.main-nav ul li a {
color: #FFF;
text-decoration: none;
padding: 20px 14px;
}
.main-nav ul {
margin-bottom: 7px !important;
}
.main-nav ul:after {
content: '';
display: block;
clear: both;
}
.main-nav ul li a:hover {
background-color: #0098aa;
}
.main-nav ul li a:active {
background-color: #6A006A;
}
.time {
background: #5e2d91;
color: #FFFFFF;
border-color: #718b88;
font-family: sans-serif;
font-weight: bold;
border-style: solid;
margin-left: 10%;
width: 228px;
height: 33px;
margin-top: 9px;
float: right;
}
<nav class="main-nav">
<ul>
<li> Home
</li>
<li> Trade Now
</li>
<li> Transactions
</li>
<li> Performance
</li>
<li>History
</li>
<li class="time">US Markets Open in <span id="hm_timer" class="style colorDefinition size_sm">08:20:04</span>
</li>
</ul>
</nav>
Is it this what you are looking for?
Code:
.main-nav{
color:#FFF;
width:100%;
background-color:#5e2d91;
float:right;
line-height:42px;
margin-top: -3px;
}
.main-nav ul li{
display: inline;
padding: 0px 10px;
}
.main-nav ul li a{
color:#FFF;
text-decoration:none;
padding: 20px 14px;
}
.main-nav ul{
margin-bottom:7px !important;}
.main-nav ul li a:hover {
background-color:#0098aa;
}
.main-nav ul li a:active{
background-color:#6A006A;
}
.time {
float: right;
background: #5e2d91;
color: #FFFFFF;
border-color: #718b88;
font-family: sans-serif;
font-weight: bold;
border-style: solid;
margin-left: 10%;
width: 228px;
height: 33px;
margin-top: 0;
float: right;
line-height: 2.2;
}
<nav class="main-nav">
<ul>
<li> Home </li>
<li> Trade Now</li>
<li> Transactions </li>
<li> Performance </li>
<li>History </li>
<li class="time">US Markets Open in <span id="hm_timer" class="style colorDefinition size_sm">08:20:04</span> </li>
</ul>
</nav>

Creating vertical line at the center of li

I have created a html page with ul and li's to show some links and set up some background color to the li's. Now I want to add vertical line on the li's.
When I try to set up a image it is coming as shown in figure 1 but I want it to be as shown in figure 2.
figure 1
figure 2
What I have tried so far:
ul#sitemap1 {
list-style: none;
}
ul#sitemap1 li a {
background-color: #002163;
color: white;
padding: 10px;
text-decoration: none;
width: 200px;
display: block;
margin: 10px;
font-weight: bold;
}
#sitemap1 li {
clear: left !important;
margin-top: 0px !important;
padding: 10px !important;
background: url('/Images/ConnectLine.JPG') no-repeat !important;
float: inherit;
}
ul#sitemap1 li a:hover {
background-color: Orange;
}
ul#sitemap2 {
list-style: none;
}
ul#sitemap2 li a {
background-color: #002163;
color: white;
padding: 10px;
text-decoration: none;
width: 200px;
display: block;
margin: 10px;
font-weight: bold;
}
ul#sitemap2 li a:hover {
background-color: Orange;
}
ul#sitemap3 {
list-style: none;
}
ul#sitemap3 li a {
background-color: #002163;
color: white;
padding: 10px;
text-decoration: none;
width: 200px;
display: block;
margin: 10px;
font-weight: bold;
}
ul#sitemap3 li a:hover {
background-color: Orange;
}
<h1>Innovations</h1>
<ul id="sitemap1">
Home
<li>Services</li>
<li>Organizational Change</li>
<li>kit</li>
<li>Sheets</li>
</ul>
<ul id="sitemap2">
Engagement
<li>Ideas</li>
<li>WorkSmart</li>
</ul>
<ul id="sitemap3">
Related Links
<li>GO-TIME</li>
</ul>
I suggest remove the id's form the CSS, no need to duplicate the same CSS just refer to the ul tag.
You can use :after pseudo-element to create the line.
Use :last-child to remove the line form the last item.
ul {
list-style: none;
}
ul li {
width: 220px;
position: relative;
margin-bottom: 20px;
}
ul li:after {
content: "";
position: absolute;
top: 90%;
left: 50%;
height: 25px;
background: black;
width: 4px;
border-radius: 5px;
border: 2px solid white;
z-index: 100;
}
ul li:last-child:after {
display: none;
}
ul li a {
background-color: #002163;
color: white;
padding: 10px;
text-decoration: none;
width: 200px;
display: block;
margin: 10px;
font-weight: bold;
}
ul li a:hover {
background-color: Orange;
}
<h1>Innovations</h1>
<ul id="sitemap1">Home
<li>Services
</li>
<li>Organizational Change
</li>
<li>kit
</li>
<li>Sheets
</li>
</ul>
<ul id="sitemap2">Engagement
<li>Ideas
</li>
<li>WorkSmart
</li>
</ul>
<ul id="sitemap3">Related Links
<li>GO-TIME
</li>
</ul>
you can use a pseudo element ::after in the a child of li
Note you can only have li as direct childs of ul. otherwise it is invalid HTML
I tweaked your CSS removing duplicated properties.
ul {
list-style: none;
margin-top: 30px
}
ul li a {
background-color: #002163;
color: white;
padding: 10px;
text-decoration: none;
width: 200px;
display: block;
margin: 10px;
font-weight: bold;
position: relative
}
ul li a::after {
position: absolute;
top: 100%;
left: 50%;
background: black;
width: 5px;
height: 100%;
content: ""
}
ul li:last-of-type a::after {
background: transparent;
height: 0
}
ul li a:hover {
background-color: Orange;
}
<div>
<h1>Innovations</h1>
<ul id="sitemap1">
<li>Home
</li>
<li>Services
</li>
<li>Organizational Change
</li>
<li>kit
</li>
<li>Sheets
</li>
</ul>
<ul id="sitemap2">
<li>Engagement
</li>
<li>Ideas
</li>
<li>WorkSmart
</li>
</ul>
<ul id="sitemap3">
<li>Related Links
</li>
<li>GO-TIME
</li>
</ul>
Try this, same you could try for sitemap 1 and 3.
ul#sitemap2 li::after{
content:'';
border:3px solid #111;
height:50px;
margin-left:110px;
}

css and html drop down menu

hey i was learning how to use the drop down menu with css, but i faced two problems:
The length of my first drop down menu changes, even though i kept playing with their percentages.
I am not able to bring my second drop down menu, i guess i don't know how to call the second drop down menu in css even though i gave it a different class name.
Here is the HTML code just for the drop down menu:
<div class="list">
<ul class="style">
<li class="international">International
<ul class="sub1">
<li class> Top 10</li>
<li> All</li>
</ul>
</li>
<li class="pop">Pop
<ul class="sub1" >
<li> Top 10</li>
<li> All</li>
</ul>
</li>
<li class="electronic">Electronic
<ul class="sub1">
<li> Top 10</li>
<li> All
<ul class="sub2">
<li> English</li>
<li> European</li>
<li> International</li>
</ul>
</li>
</ul>
</li>
</div>
and here is the CSS code:
div ul li {
display:inline-block;
background-color:#B2B28F;
float:right;
text-align: center;
width: 22%;
position: relative;
z-index: 1;
bottom: 19px;
padding-top: 5px;
font-size: 18px;
padding-bottom: 3px;
font-weight: bold;
font-family: harrington;
margin-right: 12px;
border-bottom:5px;
margin-bottom: 10px;
text-align: center;
margin-top: 2px;
}
div ul li a {
display: block;
height: 30px;
text-align: center;
border-bottom:5px;
position: relative;
font-size: 20;
z-index: 1;
margin-top: 2px;
}
.sub1 li {
display: none;
position:relative;
width:100%;
height: 20px;
margin-bottom:-8px;
margin-top:12px ;
float: right;
font-size: 17;
margin-right: 4px;
padding: 2px;
text-align: center;
left:-20px;
}
.sub1 li a {
text-align: left;
margin-right: 15px;
}
.sub2 li {
position: relative;
left: 15px;
top: -30px;
width: 100%;
text-align: left;
margin-top: -3px;
margin-bottom: 4px;
display: none;
float: left;
}
div ul li:hover ul li{
display: block;
position: absolute;
top: 27px;
float: left;
width: 97%;
left: 0px;
height: 23px;
border-top: 5px;
text-align: center;
}
div ul li :hover ul li ul li {
display: block;
position: absolute;
text-align: center;
}
a:link {
text-decoration: none;
}
a:visited {
color:#520029;
}
a:hover {
color: #293D66;
}
also any comments on how i did would be appreciated!
Hope you like this..
Just made some changes on your html and css.
HTML:
<div class="nav">
<ul>
<li>International
<ul>
<li> Top 10</li>
<li> All</li>
</ul>
</li>
<li>Pop
<ul>
<li> Top 10</li>
<li> All</li>
</ul>
</li>
<li>Electronic
<ul>
<li> Top 10</li>
<li> All
<ul>
<li> English</li>
<li> European</li>
<li> International</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
CSS:
.nav {
margin: 50px auto;
text-align: center;
}
.nav ul ul {
display: none;
}
.nav ul li:hover > ul {
display: block;
}
.nav ul {
background: #C0C0C0;
padding: 0 20px;
list-style: none;
position: relative;
display: inline-table;
}
.nav ul:after {
content: ""; clear: both; display: block;
}
.nav ul li {
float: left;
}
.nav ul li:hover {
background: #4b545f;
}
.nav ul li:hover a {
color: #fff;
}
.nav ul li a {
display: block; padding: 10px 20px;
color: #757575; text-decoration: none;
}
.nav ul ul {
background: #5f6975; padding: 0;
position: absolute; top: 100%;
}
.nav ul ul li {
float: none;
border-top: 1px solid #6b727c;
border-bottom: 1px solid #575f6a; position: relative;
}
.nav ul ul li a {
padding: 15px 40px;
color: #fff;
}
.nav ul ul li a:hover {
background: #4b545f;
}
.nav ul ul ul {
position: absolute; left: 100%; top:0;
}
Also Here is the fiddle, Check this working here
I would recommend not using absolute positioning and floats to elements that don't need it..
regarding your second sub, I got it working in this example..
div > ul > li {
display:inline-block;
background-color:#B2B28F;
float:right;
text-align: center;
width: 22%;
position: relative;
z-index: 1;
bottom: 19px;
padding-top: 5px;
font-size: 18px;
padding-bottom: 3px;
font-weight: bold;
font-family: harrington;
margin-right: 12px;
border-bottom:5px;
margin-bottom: 10px;
text-align: center;
margin-top: 2px;
}
div ul li a {
display: block;
text-align: center;
padding:5px 0;
position: relative;
font-size: 20px;
z-index: 1;
color:#212121;
padding-left:10px; box-sizing:border-box;
}
ul { padding:0;}
ul li { list-style:none;}
.sub1 { display:none; width:100%;}
.sub1 li {
position:relative;
width:100%;
clear:both;
font-size: 17px;
text-align: center;
}
.sub1 li a {
text-align: left;
}
.sub2 { display:none; position: relative; background:#B2B28F;}
.sub2 li {
width: 100%;
text-align: left;
margin-bottom: 4px;
padding-left:20px;
box-sizing:border-box;
}
.sub2 li a { font-size:14px;}
div ul li:hover ul li{
width: 100%;
left: 0px;
border-top: 5px solid;
text-align: center;
}
div ul li:hover > ._sub { display:block;}
a:link {
text-decoration: none;
}
a:visited {
color:#520029;
}
a:hover {
color: #293D66;
}
http://jsfiddle.net/2mSzr/
notice I make more specific rules with the '>' option in css, so the styling rules will not
apply to the wrong elements..
Also in the HTML I've added _sub class to all sub menus, and changed the behavior so the display:none/block will be on the actual ul._sub elements and not on their li's.. it just
makes more sense..
go over the example above, let me know if you have any questions.