I have a CMS-generated main-nav menu with one sub-menu. Both menus are standard ul tags with a class of “navCMSListMenuUL” which is then styled in my CSS accordingly. The issue is that on a:hover, the container expands to accommodate the newly displayed sub-nav ul.
I would like for the sub-nav to go outside of the container and flow at a higher z-index than any elements beneath the container. There are a couple of other things that I would like to clean up in this nav, but those are ancillary to the sub-nav flow. I have created a reduced test-case in Codepen # http://codepen.io/patrickTheWizard/pen/ZGWKYX .
<nav class="navigation">
<ul id="menuElem" class="navCMSListMenuUL">
<li class="navCMSListMenuLI">
<a class="navCMSListMenuLink" href="#">Home</a>
</li>
<li class="navCMSListMenuLI">
<a class="navCMSListMenuLink" href="#">About Us</a>
</li>
<li class="navCMSListMenuLI">
<a class="navCMSListMenuLink" href="#">Calendar</a>
</li>
<li class="navCMSListMenuHighlightedLI noseparator">
<a class="navCMSListMenuLinkHighlighted" href="#">Members</a>
<ul class="navCMSListMenuUL">
<li class="navCMSListMenuLI">
<a class="navCMSListMenuLink" href="#">Become a Member</a>
</li>
<li class="navCMSListMenuLI">
<a class="navCMSListMenuLink" href="#">Board Meetings</a>
</li>
<li class="navCMSListMenuLI">
<a class="navCMSListMenuLink" href="#">Committees</a>
</li>
<li class="navCMSListMenuLI">
<a class="navCMSListMenuLink" href="#">Current Members</a>
</li>
<li class="navCMSListMenuLI">
<a class="navCMSListMenuLink" href="#">Member Benefits</a>
</li>
<li class="navCMSListMenuLI noseparator">
<a class="navCMSListMenuLink" href="#">Statistics & Data</a>
</li>
</ul>
</li>
</ul>
/* #01-Header/Nav# */
nav.navigation {
clear: both;
/* background-color: #3c3c3c; */
overflow: visible;
/* padding: 15px; */
/* border-top: 6px solid #2a8cec; */
/* margin-bottom: 30px; */
}
ul#menuElem {
text-align: center;
background-color: #3c3c3c;
border-top: 6px solid #2a8cec;
margin-bottom: 30px;
}
ul#menuElem li {
display: inline-block;
margin: 16px 0 15px 0;
}
ul#menuElem a {
color: #fff;
text-decoration: none;
padding: 15px 35px;
font-weight: 600;
text-transform: uppercase;
border-right: 1px solid;
margin: 15px 0;
margin-left: -4px;
}
ul#menuElem a:hover {
background-color: #2a8cec;
}
ul#menuElem li ul {
display: none;
width: 100%;
float: left;
}
ul#menuElem li:hover ul {
display: block;
}
ul#menuElem ul li {
display: block;
}
OK, you when doing menu-like code, you are going to have styles that override each other (multiple nested UL, LI and A).
It's good practice to include the ">" element in your style sheets, which limits the scope of your query to direct children.
I have edited your code a bit, mainly by introducing that direct child rule (>). I also made the sub menu absolute positioned to it's parent, meaning you will not have the sub menu push your main menu to grow large.
Here is your code pen.
And the code:
/* #01-Header/Nav# */
nav.navigation {
clear: both;
/* background-color: #3c3c3c; */
overflow: visible;
/* padding: 15px; */
/* border-top: 6px solid #2a8cec; */
/* margin-bottom: 30px; */
}
ul#menuElem {
text-align: center;
background-color: #3c3c3c;
border-top: 6px solid #2a8cec;
margin-bottom: 30px;
}
ul#menuElem > li {
display: inline-block;
position: relative;
margin: 16px 0 15px 0;
}
ul#menuElem > li > a {
color: #fff;
text-decoration: none;
padding: 15px 35px;
font-weight: 600;
text-transform: uppercase;
border-right: 1px solid;
margin: 15px 0;
margin-left: -4px;
}
ul#menuElem > li > a:hover {
background-color: #2a8cec;
}
ul#menuElem > li > ul {
display: none;
width: 100%;
float: left;
}
ul#menuElem > li:hover ul {
display: block;
top: 30px;
right: 0px;
position: absolute;
background: #FFF;
padding: 0px;
margin: 0px;
}
ul#menuElem > li:hover > ul > li{
margin: 0px;
padding: 0px;
list-style: none;
text-align: left;
padding: 5px;
line-height: 30px;
border-bottom: solid 1px #dedede;
}
ul#menuElem > li:hover > ul > li > a{
text-decoration: none;
color: inherit;
}
ul#menuElem > li:hover > ul > li:hover {
background: #000;
color: #FFF;
}
ul#menuElem > ul > li {
display: block;
}
Related
This question already has answers here:
How to style the parent element when hovering a child element?
(8 answers)
Closed 3 years ago.
I have a navigation bar that is outputs a border-bottom when i hover over the li but when i hover over the child elements of that li, the :hover stops, how do i make it so that the :hover remains even when i hover over the child elements.
I would like to add some parts of the code. This is the HTML file.
* {
margin: 0;
padding: 0;
border: 0;
}
` header {
background: #fff;
width: 100%;
}
.navbar {
padding: 0;
}
.navbar nav {
width: 100%;
height: 115px;
}
.navbar nav ul {
float: right;
margin: 0;
}
.navbar nav ul li {
text-decoration: none;
float: left;
list-style: none;
position: relative;
}
.navbar nav ul li a {
color: black;
display: block;
padding: 45.5px 14px;
text-decoration: none;
}
.parent-a:hover {
border-bottom: #aa312c 4px solid;
padding: 25.5px 14px;
margin: 18px 0;
}
.level2-ul:hover .parent-a {
border-bottom: #aa312c 4px solid;
padding: 25.5px 14px;
margin: 18px 0;
}
.navbar nav ul li ul {
display: none;
position: absolute;
background-color: white;
padding: 0;
border-radius: 0px 0px 4px 4px;
}
.navbar nav ul li:hover ul {
display: block;
background-color: rgb(234, 236, 237);
z-index: 100;
}
.navbar nav ul li ul li {
width: 180px;
border-radius: 4px;
}
.navbar nav ul li ul li a {
color: black;
padding: 8px 14px;
border-bottom: 1px solid #dedfe1;
}
.navbar nav ul li ul li a:hover {
background: #dedfe1;
}
#headline {
color: #fff;
padding: 4px;
font-size: 1.5rem;
margin: 0;
text-align: center;
font-weight: bold;
}
#headline-wrapper {
background: #aa312c;
}
<header>
<div id="header-wrapper">
<div class="body" id="logo-wrapper">
<!-- Navigation start -->
<div class="navbar">
<nav>
<ul>
<li>
<a class="parent-a" href="#">Online Activities</a>
<ul>
<li class="level2-ul">Google</li>
<li class="level2-ul">Youtube</li>
<li class="level2-ul">Reddit</li>
</ul>
</li>
<li>
<a class="parent-a" href="#">Social Media</a>
<ul>
<li>Facebook</li>
<li>Instagram</li>
<li>Twitter</li>
</ul>
</li>
<li>
<a class="parent-a" href="#">Online Shopping</a>
<ul>
<li>Shopee</li>
<li>Lazada</li>
<li>Carousell</li>
</ul>
</li>
</ul>
</nav>
</div>
</div>
<div id="headline-wrapper">
<h2 id="headline" class="text-center text-uppercase">
Software Quotation Tool
</h2>
</div>
</div>
</header>
By doing this, I can hover over the 3 nav lis and :hover would be activated. However, as soon as I hover over the inner li, the :hover stopped, I tried using .level2-ul but unable to do so. Thank you for the help.
Put parent-a on the li rather than on the a.
* {
margin: 0;
padding: 0;
border: 0;
}
` header {
background: #fff;
width: 100%;
}
.navbar {
padding: 0;
}
.navbar nav {
width: 100%;
height: 115px;
}
.navbar nav ul {
float: right;
margin: 0;
}
.navbar nav ul li {
text-decoration: none;
float: left;
list-style: none;
position: relative;
}
.navbar nav ul li a {
color: black;
display: block;
padding: 45.5px 14px;
text-decoration: none;
}
.parent-a:hover > a {
border-bottom: #aa312c 4px solid;
padding: 25.5px 14px;
margin: 18px 0;
}
.level2-ul:hover .parent-a {
border-bottom: #aa312c 4px solid;
padding: 25.5px 14px;
margin: 18px 0;
}
.navbar nav ul li ul {
display: none;
position: absolute;
background-color: white;
padding: 0;
border-radius: 0px 0px 4px 4px;
}
.navbar nav ul li:hover ul {
display: block;
background-color: rgb(234, 236, 237);
z-index: 100;
}
.navbar nav ul li ul li {
width: 180px;
border-radius: 4px;
}
.navbar nav ul li ul li a {
color: black;
padding: 8px 14px;
border-bottom: 1px solid #dedfe1;
}
.navbar nav ul li ul li a:hover {
background: #dedfe1;
}
#headline {
color: #fff;
padding: 4px;
font-size: 1.5rem;
margin: 0;
text-align: center;
font-weight: bold;
}
#headline-wrapper {
background: #aa312c;
}
<header>
<div id="header-wrapper">
<div class="body" id="logo-wrapper">
<!-- Navigation start -->
<div class="navbar">
<nav>
<ul>
<li class="parent-a" >
Online Activities
<ul>
<li class="level2-ul">Google</li>
<li class="level2-ul">Youtube</li>
<li class="level2-ul">Reddit</li>
</ul>
</li>
<li class="parent-a">
Social Media
<ul>
<li>Facebook</li>
<li>Instagram</li>
<li>Twitter</li>
</ul>
</li>
<li class="parent-a">
Online Shopping
<ul>
<li>Shopee</li>
<li>Lazada</li>
<li>Carousell</li>
</ul>
</li>
</ul>
</nav>
</div>
</div>
</div>
</header>
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>
I have horizontal menu bar, and I trying to add sub menu for one of item, but I am not able to add it, Its appending to my main menu, please someone help me to where i missing
thanks
HTML
<div id="talltabs-maroon">
<ul>
<li class="first">Home <span>Page</span></li>
<li class="active"><span>About us</span></li>
<li class="dropdown"><a class="dropbtn" href="#"> <span> Report </span></a>
<ul class="dropdown-content" style="left:0">
<li>
<a href="">
<p>Valve Report</p>
</a>
</li>
<li>
<a href="">
<p>Cylinder Report</p>
</a>
</li>
</ul>
</li>
<li class="last">Contact <span>Us</span></li>
</ul>
</div>
CSS for Main menu
#talltabs-maroon {
clear: left;
float: left;
padding: 0;
border-top: 3px solid #CD324F;
width: 100%;
overflow: hidden;
font-family: Georgia, serif;
height: 90px;
position: inherit;
}
#talltabs-maroon ul {
float: left;
margin: 0;
padding: 0;
list-style: none;
position: relative;
left: 50%;
text-align: center;
}
#talltabs-maroon ul li {
display: block;
float: left;
list-style: none;
margin: 0;
padding: 0;
position: relative;
right: 50%;
}
#talltabs-maroon ul li a {
display: block;
float: left;
margin: 0 3px 0 0;
padding: 0px 10px 6px 10px;
background: #CD324F;
text-decoration: none;
color: #fff;
}
#talltabs-maroon ul li a p:hover {
color: aqua;
}
#talltabs-maroon ul li a:hover {
padding: 20px 10px 6px 10px;
color: black
}
#talltabs-maroon ul li.active a,
#talltabs-maroon ul li.active a:hover {
padding: 25px 10px 6px 10px;
border-width: 5px;
border-color: aqua;
color: aqua;
}
CSS for drop down menu i tried.
.dropbtn {
list-style-type: none;
color: white;
padding: 14px;
font-size: 14px;
border: none;
cursor: pointer;
}
.dropdown {
position: relative;
display: block;
}
.dropdown-content {
list-style-type: none;
display: none;
position: absolute;
right: 0;
/*background-color: black;*/
background-image: url('../../Images/black-olive.jpg'); /*dropdowm popup*/
min-width: 160px;
box-shadow: 0px 8px 16px 5px rgba(0,0,0,0.2);
z-index: 1;
padding-right: 2px;
margin-right: 2px;
}
.dropdown-content a {
color: white;
padding: 10px 14px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {
/*background-color: gray;*/
color: black;
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown:hover .dropbtn {
/*background-color: #3e8e41;*/
}
pleas help me.
thanks
tink.
Here is my answer for same example, I changed complete css,
body {
font-family: 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
ul {
text-align: left;
display: inline;
margin: 0;
padding: 15px 4px 17px 0;
list-style: none;
}
ul li {
display: inline-block;
margin-right: -1px;
position: relative;
padding: 15px 20px;
background: #CD324F;
cursor: pointer;
color: black;
height: 40px;
width: auto;
text-align:center;
}
ul li a{
color:black;
}
ul li:hover {
background: #CD324F;
color: #fff;
height: 45px;
}
ul li a:hover {
color: #fff;
}
ul li ul {
padding: 0;
position: absolute;
top: 68px;
left: 0;
width: 160px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
display: none;
opacity: 0;
visibility: hidden;
}
ul li ul li {
background: #ce5068;
display: block;
color: #CD324F;
height: 35px;
}
ul li ul li:hover {
background: #CD324F;
height: 35px;
}
ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
<div style="height: 77px; width:100%; margin-top:65px;text-align:center; border-top:solid; border-top-color:#CD324F">
<ul><li>Home</li>
<li>About</li>
<li>
Portfolio
<ul>
<li>Web Design</li>
<li>Web Development</li>
<li>Illustrations</li>
</ul>
</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</div>
Result: on hover portfolio, drop down will appear
Working example on JSFiddle.
I really recommend to look at bootstrap's drop down menu. It is easy to use and most things are already done for you. good luck
Here is the link: https://www.w3schools.com/bootstrap/bootstrap_dropdowns.asp
your code is bit confusing , i have created a simple demo for you how to do it.
here is my HTML code
body {
background: #212121;
font-size:22px;
line-height: 32px;
color: #ffffff;
word-wrap:break-word !important;
font-family: 'Open Sans', sans-serif;
}
h1 {
font-size: 60px;
text-align: center;
color: #FFF;
}
h3 {
font-size: 30px;
text-align: center;
color: #FFF;
}
h3 a {
color: #FFF;
}
a {
color: #FFF;
}
h1 {
margin-top: 100px;
text-align:center;
font-size:60px;
font-family: 'Bree Serif', 'serif';
}
#container {
margin: 0 auto;
}
p {
text-align: center;
}
nav {
margin: 50px 0;
background-color: #E64A19;
}
nav ul {
padding: 0;
margin: 0;
list-style: none;
position: relative;
}
nav ul li {
display:inline-block;
background-color: #E64A19;
}
nav a {
display:block;
padding:0 10px;
color:#FFF;
font-size:20px;
line-height: 60px;
text-decoration:none;
}
nav a:hover {
background-color: #000000;
}
/* Hide Dropdowns by Default */
nav ul ul {
display: none;
position: absolute;
top: 60px; /* the height of the main nav */
}
/* Display Dropdowns on Hover */
nav ul li:hover > ul {
display:inherit;
}
/* Fisrt Tier Dropdown */
nav ul ul li {
width:170px;
float:none;
display:list-item;
position: relative;
}
<div id="container">
<nav>
<ul>
<li>Home</li>
<li>WordPress
<!-- First Tier Drop Down -->
<ul>
<li>Themes</li>
<li>Plugins</li>
<li>Tutorials</li>
</ul>
</li>
<li>Web Design
<!-- First Tier Drop Down -->
<ul>
<li>Resources</li>
<li>Links</li>
<li>Tutorials
</ul>
</nav>
</div>
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;
}
I'd like to have the navigation bar centered and the text placed to left as it is, but when I add the h3-tag the navigation bar moves to the right. How can I do this?
html,
body {
height: 100%;
margin: 0;
padding: 0;
width: 100%;
}
#toptext {
margin: 5px 0px 0px 10px;
padding: 0;
display: inline-block;
float: left;
font-style: bold;
font-size: 2em;
color: white;
}
.nav ul {
list-style: none;
background-color: #444;
text-align: center;
padding: 0;
margin: 0;
}
.nav li {
font-family: 'Oswald', sans-serif;
font-size: 1.2em;
line-height: 40px;
text-align: left;
}
.nav a {
text-decoration: none;
color: #fff;
display: block;
padding-left: 15px;
border-bottom: 1px solid #888;
transition: .3s background-color;
}
.nav a:hover {
background-color: #005f5f;
}
.nav a.active {
background-color: #aaa;
color: #444;
cursor: default;
}
/* Sub Menus */
.nav li li {
font-size: .8em;
}
/*******************************************
Style menu for larger screens
Using 650px (130px each * 5 items), but ems
or other values could be used depending on other factors
********************************************/
#media screen and (min-width: 650px) {
.nav li {
width: 130px;
border-bottom: none;
height: 50px;
line-height: 50px;
font-size: 1em;
display: inline-block;
margin-right: -4px;
}
.nav a {
border-bottom: none;
}
.nav > ul > li {
text-align: center;
}
.nav > ul > li > a {
padding-left: 0;
}
/* Sub Menus */
.nav li ul {
position: absolute;
display: none;
width: inherit;
}
.nav li:hover ul {
display: block;
}
.nav li ul li {
display: block;
}
}
<div class="nav">
<h3 id="toptext">Text text text text</h3>
<ul>
<li class="home"><a class="active" href="#">Home</a>
</li>
<li class="about">About
</li>
<li>Other
<ul>
<li>Site1
</li>
<li>Site2
</li>
</ul>
</li>
<li class="contact">Contact
</li>
</ul>
</div>
I used the navigation bar from: http://css-snippets.com/drop-down-navigation/
Anything that is in the document flow is going to affect the position of the menu. So you would would have to take the h3 out of the flow by positioning it absolutely.
#toptext {
margin: 5px 0px 0px 10px;
padding: 0;
font-style: bold;
font-size: 2em;
color: white;
position: absolute;
}
This has other issues but solves your initial problem.
html,
body {
height: 100%;
margin: 0;
padding: 0;
width: 100%;
}
#toptext {
margin: 5px 0px 0px 10px;
padding: 0;
/*
display: inline-block;
float: left;
*/
font-style: bold;
font-size: 2em;
color: white;
position: absolute;
}
.nav ul {
list-style: none;
background-color: #444;
text-align: center;
padding: 0;
margin: 0;
}
.nav li {
font-family: 'Oswald', sans-serif;
font-size: 1.2em;
line-height: 40px;
text-align: left;
}
.nav a {
text-decoration: none;
color: #fff;
display: block;
padding-left: 15px;
border-bottom: 1px solid #888;
transition: .3s background-color;
}
.nav a:hover {
background-color: #005f5f;
}
.nav a.active {
background-color: #aaa;
color: #444;
cursor: default;
}
/* Sub Menus */
.nav li li {
font-size: .8em;
}
/*******************************************
Style menu for larger screens
Using 650px (130px each * 5 items), but ems
or other values could be used depending on other factors
********************************************/
#media screen and (min-width: 650px) {
.nav li {
width: 130px;
border-bottom: none;
height: 50px;
line-height: 50px;
font-size: 1em;
display: inline-block;
margin-right: -4px;
}
.nav a {
border-bottom: none;
}
.nav > ul > li {
text-align: center;
}
.nav > ul > li > a {
padding-left: 0;
}
/* Sub Menus */
.nav li ul {
position: absolute;
display: none;
width: inherit;
}
.nav li:hover ul {
display: block;
}
.nav li ul li {
display: block;
}
}
<div class="nav">
<h3 id="toptext">Text text text text</h3>
<ul>
<li class="home"><a class="active" href="#">Home</a>
</li>
<li class="about">About
</li>
<li>Other
<ul>
<li>Site1
</li>
<li>Site2
</li>
</ul>
</li>
<li class="contact">Contact
</li>
</ul>
</div>
Its because your h3 is inside the nav div. try making the h3 absolute positioned and your .nav class relatively positioned.