CSS3/HTML5 dropdown menu - html

Been trying to fix my code for a couple of hours and I just can't. I want to have my navbar have a dropdown function. But I can't seem to make it work.
As you can see I've start on the dropdown menu class, but I can't figure where to go from there. Been googling, and found a lot of examples, tried to copy/paste some of the bits, with no good results. So I was thinking that you might be able to help.
nav {
display: block;
background-color: indianred;
box-shadow: 0px 10px 5px #888888;
}
nav ul {
text-align: center;
}
nav ul li {
display: inline-block;
padding: 20px;
}
nav ul li a {
width: 125px;
color: black;
padding: 20px;
background-color: blueviolet;
text-decoration: none;
}
nav ul li a:hover {
background-color: aqua;
}
.dropdown {
display: none;
}
<nav>
<ul>
<li>FORSIDE
</li>
<li>ERHVERVSUDDANNELSER
<ul class="dropdown">
<li>content 1</li>
<li>content 1</li>
<li>content 1</li>
<li>content 1</li>
</ul>
</li>
<li>EUX
</li>
<li>HTX
</li>
<li>OM TECH COLLEGE
</li>
</ul>
</nav>

ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a, .dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover, .dropdown:hover .dropbtn {
background-color: red;
}
li.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {background-color: #f1f1f1}
.dropdown:hover .dropdown-content {
display: block;
}
<ul>
<li>Home</li>
<li>News</li>
<li class="dropdown">
Dropdown
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</li>
</ul>
for more detail visit Dropdown Menu in Navbar

Change the CSS to this:
nav {
display: block;
background-color: indianred;
box-shadow: 0px 10px 5px #888888;
}
nav ul {
text-align: center;
}
nav ul li {
display: inline-block;
padding: 20px;
position:relative;
}
nav ul li a {
width: 125px;
color: black;
padding: 20px;
background-color: blueviolet;
text-decoration: none;
}
nav ul li a:hover {
background-color: aqua;
}
nav ul li ul {
display:none;
}
nav ul li:hover ul {
display:block;
position:absolute;
background:indianred;
}
<nav>
<ul>
<li>FORSIDE</li>
<li>ERHVERVSUDDANNELSER
<ul class="dropdown">
<li>content 1</li>
<li>content 1</li>
<li>content 1</li>
<li>content 1</li>
</ul>
</li>
<li>EUX</li>
<li>HTX</li>
<li>OM TECH COLLEGE</li>
</ul>
</nav>
You wanted to hide the dropdown but then show it when you hover over the dropdown's parent element.
I then made the parent li position:relative; and the dropdown position:absolute so it didn't push any of the other dropdown menu items anywhere it shouldn't be, but didn't style it past giving it a background colour.

you need to write css for the element on hover
like
element1:hover tobeshownele{display:block;}

You can try something like this. Didn't want to change too much so the code and UI are still quite messy.
nav {
display: block;
background-color: indianred;
box-shadow: 0px 10px 5px #888888;
}
nav ul {
text-align: center;
}
nav ul li {
display: inline-block;
margin: 20px;
}
nav ul li a {
width: 125px;
color: black;
padding: 20px;
background-color: blueviolet;
text-decoration: none;
}
nav ul li a:hover {
background-color: aqua;
}
.dropdown {
display: none;
position: absolute;
}
nav ul li:hover .dropdown {
display: block;
}
ul.dropdown li {
display: block;
padding: 10px;
}
<nav>
<ul>
<li>FORSIDE</li>
<li>ERHVERVSUDDANNELSER
<ul class="dropdown">
<li>content 1</li>
<li>content 1</li>
<li>content 1</li>
<li>content 1</li>
</ul>
</li>
<li>EUX</li>
<li>HTX</li>
<li>OM TECH COLLEGE</li>
</ul>
</nav>

Related

How to float search icon to the right

How do i float the font awesome search icon to the right next to sign up.
Here is a screenshot of my nav bar, so you know what i am referring too:
https://imgur.com/rE23FfB
I have search the internet for tutorials and they all say to use float: right; but that seems to not work
body {
margin: 0;
padding: 0;
margin-top: 130px;
overflow-x: hidden;
}
.nav-menu a img {
float: left;
margin-left: 10px;
}
.nav-menu ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: rgba(0, 0, 0, 0.9);
margin-top: -130px;
}
.nav-menu li {
float: left;
}
.nav-menu li a,
.dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav-menu li a:hover,
.dropdown:hover .dropbtn {
border-top: 2px solid #ff0000;
}
.nav-menu li.dropdown {
display: inline-block;
}
.nav-menu .dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.nav-menu .dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.nav-menu .dropdown-content a:hover {
background-color: #ff0000;
color: #fff;
}
.nav-menu .dropdown:hover .dropdown-content {
display: block;
}
.nav-menu li.social {
float: right;
}
<div class="nav-menu">
<ul>
<img src="img/logo.jpg" style="width:50px">
<li class="dropdown">
Games
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</li>
<li class="dropdown">
Crews
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</li>
<li>Jobs</li>
<li>Photos</li>
<li>Videos</li>
<li>Events</li>
<li>News</li>
<li class="social">
Sign In
Sign Up
<li><i class="fas fa-search"></i></li>
</ul>
The problem is your <li> wrapping the search icon. This is an invalid code. <li> cannot be a children of an <li>. Change it to just an <a> element
body {
margin: 0;
padding: 0;
margin-top: 130px;
overflow-x: hidden;
}
.nav-menu a img {
float: left;
margin-left: 10px;
}
.nav-menu ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: rgba(0, 0, 0, 0.9);
margin-top: -130px;
}
.nav-menu li {
float: left;
}
.nav-menu li a,
.dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav-menu li a:hover,
.dropdown:hover .dropbtn {
border-top: 2px solid #ff0000;
}
.nav-menu li.dropdown {
display: inline-block;
}
.nav-menu .dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.nav-menu .dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.nav-menu .dropdown-content a:hover {
background-color: #ff0000;
color: #fff;
}
.nav-menu .dropdown:hover .dropdown-content {
display: block;
}
.nav-menu li.social {
float: right;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
<div class="nav-menu">
<ul>
<li><img src="img/logo.jpg" style="width:50px"></li>
<li class="dropdown">
Games
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</li>
<li class="dropdown">
Crews
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</li>
<li>Jobs</li>
<li>Photos</li>
<li>Videos</li>
<li>Events</li>
<li>News</li>
<li class="social">
Sign In
Sign Up
<i class="fas fa-search"></i>
</li>
</ul>
</div>
I know I'm a little late to the question - but I have an improved solution (at least I think so)!
The syntax on the previous answer is still a little incorrect. You should also try to make your dropdowns into nested ul's. :-)
By using the display: flex and align-items: center on the .nav-menu, you will be aligning all the elements up without the use of float (which I tend to avoid anyway as it often makes your code behave like you would not expect).
I've also added margin-left:auto for you on your .social container, it will push all your social to the end of the parent.
EDIT:
If you use border-top: transparent on the menu items, this makes sure that the text doesn't move when you add in a coloured border on :hover - so you're essentially just showing the colour.
html,
body {
margin: 0;
padding: 0;
}
.nav-menu {
display: flex;
align-items: center;
background-color: rgba(0, 0, 0, 0.9);
}
.nav-menu img {
margin: 0 10px;
}
.nav-menu>ul {
list-style-type: none;
margin: 0;
padding: 0;
display: flex;
}
ul.social {
margin-left: auto;
}
.nav-menu li a,
.dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
border-top: 2px solid transparent;
}
.nav-menu li a:hover,
.dropdown:hover .dropbtn {
border-top: 2px solid #ff0000;
}
.nav-menu li.dropdown {
display: inline-block;
}
.nav-menu .dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
list-style: none;
margin: 0;
padding: 0;
}
.nav-menu .dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.nav-menu .dropdown-content a:hover {
background-color: #ff0000;
color: #fff;
}
.nav-menu .dropdown:hover .dropdown-content {
display: block;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css">
<!-- just for the example -->
<div class="nav-menu">
<img src="img/logo.jpg" style="width:50px">
<ul>
<li class="dropdown">
Games
<ul class="dropdown-content">
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
</ul>
</li>
<li class="dropdown">
Crews
<ul class="dropdown-content">
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
</ul>
</li>
<li>Jobs</li>
<li>Photos</li>
<li>Videos</li>
<li>Events</li>
<li>News</li>
</ul>
<ul class="social">
<li>Sign In</li>
<li>Sign Up</li>
<li><i class="fas fa-search"></i></li>
</ul>
</div>
You can see the full effect if you view the snippet in full screen.

html css ul and button issue

Hi so in this my explore more button and my ul list so whenever I move my explore button line height the ul and button both move together side..and I want the explore more button downward. what should I do?? I tried using other attributes but nothing worked. I am making this website for my dad's academy.
Here is my HTML code
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<header>
<div class="row">
<div>
<ul class="main-nav">
<li>Home</li>
<li>About</li>
<li>Study Visa
<ul>
<li>Australia</li>
<li>Canada</li>
<li>New Zealand</li>
</ul>
</li>
<li>Courses
<ul>
<li>Ielts</li>
<li>PTE</li>
<li>Spoken English</li>
</ul>
</li>
<li>Contact Us
</li>
<li> Login </li>
<li>Reviews</li>
</ul>
</div>
<div class="button">
Explore More
</div>
</div>
</header>
</header>
</body>
this is my CSS code
body {
background: url(abc.jpg) no-repeat;
background-size: none;
background-position : none;
background-size : cover;
margin-left: 20%;
}
.main-nav
{
margin: 0px;
padding: 0px;
list-style: none;
font-family: arial;
position: absolute
top : 20px;
}
.main-nav li {
float: left;
width: 145px;
height: 67px;
background-color: black;
opacity: 0.8;
line-height: 67px;
text-align: center;
font-size: 22px;
margin-left : px;
}
.main-nav li a {
text-decoration: none;
color: white;
display: block;
line-height : 100 px ;
}
.main-nav li a:hover {
background-color: orange;
}
.main-nav li ul li{
display: none;
}
.main-nav li:hover ul li {
display: block;
}.button
{
margin-top: 350px;
margin-left: 320px;
}
.btn
{
border: 1px solid white;
padding: 10px 30px;
color: white;
text-decoration: none;
margin-right: 89px;
font-size: 13px;
text-transform: uppercase;
}
.btn-two
{
font-family: "Roboto", sans-serif;
}
.btn-two:hover
{
background-color: darkorange;
transition: all 0.5s ease-in;
}
so I want the menu above near k academy logo.. and explore more button where it is. thanks!!
I changed up your HTML structure since there were empty tags and random closing tags. CSS i basically just removed the float on the li, since that takes it out of the flow, and instead added flexbox to the ul. Hope that helps flexbox ftw. Idk how your button ended up in that location but I would use position: absolute on that top,right,bottom,left:0 margin: auto;
body {
background: url(abc.jpg) no-repeat;
background-size: none;
background-position: none;
background-size: cover;
}
.main-nav {
display: flex;
justify-content: space-between;
alig margin: 0px;
padding: 0px;
list-style: none;
font-family: arial;
}
.main-nav li {
width: 145px;
height: 67px;
background-color: black;
opacity: 0.8;
line-height: 67px;
text-align: center;
font-size: 22px;
margin-left: px;
}
.main-nav li a {
text-decoration: none;
color: white;
display: block;
line-height: 100 px;
}
.main-nav li a:hover {
background-color: orange;
}
.main-nav li ul li {
display: none;
}
.main-nav li:hover ul li {
display: block;
}
.button {
margin-top: 350px;
margin-left: 320px;
}
.btn {
border: 1px solid white;
padding: 10px 30px;
color: white;
text-decoration: none;
margin-right: 89px;
font-size: 13px;
text-transform: uppercase;
}
.btn-two {
font-family: "Roboto", sans-serif;
}
.btn-two:hover {
background-color: darkorange;
transition: all 0.5s ease-in;
}
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<header>
<ul class="main-nav">
<li>Home</li>
<li>About</li>
<li>Study Visa
<ul>
<li>Australia</li>
<li>Canada</li>
<li>New Zealand</li>
</ul>
</li>
<li>Courses
<ul>
<li>Ielts</li>
<li>PTE</li>
<li>Spoken English</li>
</ul>
</li>
<li>Contact Us
</li>
<li> Login </li>
<li>Reviews</li>
</ul>
<div class="button">
Explore More
</div>
</header>
</body>
I hope this will help you to solve the problem.
.main-menu {
background-color: #444;
}
.main-menu nav ul {
margin: 0;
padding: 0;
}
.main-menu nav > ul > li {
display: inline-block;
position: relative;
margin: 0;
}
.main-menu nav > ul > li a {
display: block;
color: #fff;
font-size: 16px;
padding: 20px 15px;
text-decoration: none;
transition: .3s;
}
.main-menu nav > ul > li:hover > a {
color: #7AA93C;
}
.main-menu nav ul li ul {
position: absolute;
padding: 10px 0;
width: 200px;
box-shadow: 0 0 10px rgba(0,0,0,0.5);
top: 150%;
opacity: 0;
visibility: hidden;
transition: .3s;
}
.main-menu nav ul li:hover ul {
top: 100%;
opacity: 1;
visibility: visible;
}
.main-menu nav ul li ul li {
display: block;
padding: 0;
margin: 0;
}
.main-menu nav ul li ul li a {
display: block;
text-decoration: none;
padding: 6px 20px;
font-size: 14px;
color: #444;
transition: .3s;
}
.main-menu nav ul li ul li:hover a {
color: #7AA93C;
}
<div class="main-menu">
<nav>
<ul>
<li>
Home
<!-- submenu start -->
<ul class="submenu">
<li>Sub Menu</li>
<li>Sub Menu</li>
<li>Sub Menu</li>
<li>Sub Menu</li>
<li>Sub Menu</li>
</ul>
<!-- submenu end -->
</li>
<li>About</li>
<li>
Service
<!-- submenu start -->
<ul class="submenu">
<li>Sub Menu</li>
<li>Sub Menu</li>
<li>Sub Menu</li>
<li>Sub Menu</li>
<li>Sub Menu</li>
</ul>
<!-- submenu end -->
</li>
<li>Contact</li>
</ul>
</nav>
</div>

CSS Dropdown-menu not displaying when <li>-element is hovered.

I have a top navigation bar with 4 options, where I wish that while the fourth option is hovered, a dropdown-menu will display.
The navigation bar is an unordered list, and the dropdown-menu (which should be activated by the fourth option) is a div consisting of 3 links.
The list item that is supposed to display the dropdown-menu while hovered:
<li class="dropdownbutton">Contact</li>
With the help of this line of code:
.dropdownbutton:hover .dropdowncontent {
display:inline-block;
}
And this is the CSS for the dropdown-content:
.dropdowncontent {
display:none;
background-color:#333;
margin-left:272px;
width:90px;
text-align:center;
}
What am I missing?
This should be allright.
ul {
margin: 0;
padding: 0;
list-style: none;
background-color: #333;
}
ul li {
display: inline-block;
position: relative;
text-align: left;
background-color: #333;
}
ul li a {
display: block;
color: #f2f2f2;
text-align: center;
padding: 16px 15px;
text-decoration: none;
transition-duration: 0.3s;
-webkit-transition-duration: 0.3s;
font-size: 17px;
font-family: Arial;
}
ul li a:hover {
background-color: #555;
}
ul li ul.dropdown {
min-width: 100%;
display: none;
position: absolute;
z-index: 999;
left: 0;
width: 90px;
}
ul li:hover ul.dropdown {
display: block;
}
ul li ul.dropdown li {
display: block;
}
ul li ul.dropdown li a {
font-size: 14px;
padding: 10px 15px;
}
<ul>
<li>Home</li>
<li>About Us</li>
<li>Products</li>
<li>Contact
<ul class="dropdown">
<li>Option 1</li>
<li>Option 2</li>
<li>Option 3</li>
</ul>
</li>
</ul>

Dropdown menu keeps skipping away

I am creating some websites and I am always using the same dropdown method for them. However i am stuck with my dropdown menu. When I hover on it it always replaces my main navigation and well lets say that not so customer friendly.
The problem probably lies within the position values I give in my css code but I fail to find how to make the right values for my needs.
So in proper words, my navigation is fine till you hover over one with a dropdown menu then it replaces himself.
I included a JSFIDDLE to show you what i mean. There is a dropdown menu under the second link in the main navigation.
HTML:
<div id="header">
<div class="blueborder">
</div>
<section class="nav">
<div class="row">
<ul class="main-nav" id="drop-nav">
<li class="home-active">Home</li>
<li> / </li>
<div class="dropdown">
<li>Over Ons</li>
<div class="dropdown-content">
<li>Betuigenissen</li>
</div>
</div>
<li> / </li>
<li>Schilderwerken</li>
<li> / </li>
<li>Behangwerken</li>
<li> / </li>
<li>Raamdecoratie</li>
<li> / </li>
<li>Realisaties</li>
<li> / </li>
<li>Contacteer ons</li>
</ul>
</div>
</section>
</div>
CSS:
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
text-align: center;
display: none;
position: inherit;
background-color: #2C2A26;
margin-top: 40px;
color: #000;
list-style: none;
width: auto;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 998;
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown-content li a {
color: #000;
border-bottom: 0px solid #ed5d00;
}
.dropdown-content li {
padding: 10px 10px;
}
.dropdown-content li a:hover {
color: #fff;
padding-bottom: 0px;
border-bottom: 0px solid #ed5d00;
}
/* Main Navi */
.main-nav {
float: left;
list-style: none;
margin-top: 0px;
padding-top: 0px;
color: #000;
font-size: 110%;
font-weight: 600;
font-family: 'Source Sans Pro', sans-serif;
}
.main-nav li {
display: inline-block;
margin-left: 1px;
color: #fff;
}
.main-nav li a {
padding: 8px 0;
color: #000;
text-decoration: none;
text-transform: uppercase;
font-size: 90%;
border: 0;
}
.main-nav li a:hover,
.main-nav li a:active {
color: #8dcee6;
}
Change to position: absolute; on the .dropdown-content and remove the top-margin, works for me:
CSS:
.dropdown-content {
text-align: center;
display: none;
position: inherit;
background-color: #2C2A26;
color: #000;
list-style: none;
width: auto;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 998;
}
.dropdown:hover .dropdown-content {
display: block;
position: absolute;
}
https://jsfiddle.net/r3gra7ta/2/
i think Your Navigation is a little bit confused.
One of simplest method is to set the submenu within the OVER ONS
<li name="OVER ONS" ><li SUBITEM1 ></li><li SUBITEM2 ></li></li>
Here a Basic Example .
#primary_nav_wrap
{
margin-top:15px
}
#primary_nav_wrap ul
{
list-style:none;
position:relative;
float:left;
margin:0;
padding:0
}
#primary_nav_wrap ul a
{
display:block;
color:#333;
text-decoration:none;
font-weight:700;
font-size:12px;
line-height:32px;
padding:0 15px;
font-family:"HelveticaNeue","Helvetica Neue",Helvetica,Arial,sans-serif
}
#primary_nav_wrap ul li
{
position:relative;
float:left;
margin:0;
padding:0
}
#primary_nav_wrap ul li.current-menu-item
{
background:#ddd
}
#primary_nav_wrap ul li:hover
{
background:#f6f6f6
}
#primary_nav_wrap ul ul
{
display:none;
position:absolute;
top:100%;
left:0;
background:#fff;
padding:0
}
#primary_nav_wrap ul ul li
{
float:none;
width:200px
}
#primary_nav_wrap ul ul a
{
line-height:120%;
padding:10px 15px
}
#primary_nav_wrap ul ul ul
{
top:0;
left:100%
}
#primary_nav_wrap ul li:hover > ul
{
display:block
}
<h1>LOGO</h1>
<nav id="primary_nav_wrap">
<ul>
<li class="current-menu-item">HOME</li>
<li>OVERONS
<ul>
<li>Betuigenissen</li>
<li>Sub Menu 2</li>
<li>Sub Menu 3</li>
<li>Sub Menu 4
<ul>
<li>Deep Menu 1
<ul>
<li>Sub Deep 1</li>
<li>Sub Deep 2</li>
<li>Sub Deep 3</li>
<li>Sub Deep 4</li>
</ul>
</li>
<li>Deep Menu 2</li>
</ul>
</li>
</ul>
</li>
<li>Schilderwerken</li>
<li>Behangwerken</li>
<li>Raamdecoratie</li>
<li>Realisaties</li>
<li>Contacteer ons</li>
</ul>
</nav>
just change the postion to "fixed" and remove margin-top in dropdown-content then it will work fine.
.dropdown-content {
text-align: center;
display: none;
position: inherit;
background-color: #2C2A26;
color: #000;
list-style: none;
width: auto;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 998;
}

How to Line Up Sub List Items Vertically in Drop Down Menu

I'm working on a CSS hover menu and all is working except that my sub menu seems to shift one of the menu items and they don't line up vertically. I've been toying with the CSS but can't seem to figure out which setting it is.
<ul>
<li>Reports</li>
<li>Users</li>
<li>Settings</li>
<li>Admin
<ul>
<li>Sub 1</li>
<li>Sub 2</li>
<li>Sub 3</li>
</ul>
</li>
</ul>
My CSS
.navigation ul ul {
display: none;
}
.navigation ul li:hover > ul {
display: block;
position: absolute;
background-color: #CC0000;
margin-left: -77px;
}
.navigation ul ul li {
float: none;
display: list-item;
position: relative;
text-align: right;
min-width: 100px;
}
You can see this in action at: http://codepen.io/anon/pen/ZGZNqG
You have to remove padding-right attribute from the .navigation ul li:last-child. Because you have given the other lis a padding of 10px in .navigation ul li styles...
.navigation {
border: 1px solid black;
}
.navigation a {
text-decoration: none;
color: #000000;
}
.navigation a:hover {
text-decoration: underline;
}
.navigation ul {
list-style: none;
margin: 0px 0px 0px 0px;
}
.u-pull-right li:last-child {
padding: 2px 0px 2px 10px;
}
#admin-list li{
padding: 2px 0px 2px 0px;
}
.navigation ul li {
display: inline-block;
padding: 2px 10px 2px 10px;
}
.navigation ul li:first-child {
padding-left: 0px;
}
.navigation ul li.active {
font-weight: bold;
}
.navigation ul ul {
display: none;
}
.navigation ul li:hover > ul {
display: block;
position: absolute;
background-color: #CC0000;
margin-left: -77px;
}
.navigation ul ul li {
float: none;
display: list-item;
position: relative;
text-align: right;
min-width: 100px;
}
<div class="row navigation no-print">
<ul class="u-pull-right">
<li>Reports
</li>
<li>Users
</li>
<li>Settings
</li>
<li id="admin-list">Admin
<ul>
<li>Sub 1</li>
<li>Sub 2</li>
<li>Sub 3</li>
</ul>
</li>
</ul>
</div>