I'm trying to create a CSS dropdown menu but have run into an issue where some style elements remain and some do not. In my codepen example you'll notice that when you hover over "Competencies" the background changes to a dark blue and the the text to white but when you move to the next list item, the text changes back to the original dark blue color. I'd like for it to remain white. I've tried removing the color attribute from nav ul li a.
nav ul li a {
display: block; padding: 1em 2em;
color: #003c7d; text-decoration: none;
font-size:1.15em;
}
nav ul li a:hover {
color:#fff;
}
http://codepen.io/anon/pen/aDBeK
just add code in css: (please run code in full screen)
nav li:hover > a, nav li a.active {
color:#FFFFFF;
}
body {
font-size:14px;
font-family: Arial;
line-height: 1.5;
}
main {
width:100%;
}
header {
margin-bottom:10px;
width:80%;
vertical-align:middle;
/*box-shadow: 0px 5px 3px rgba(0,0,0,0.25);*/
}
select {
margin-top:10px;
font-size:1em;
}
nav ul {
background: background: rgba(255, 255, 255, 0.1);
vertical-align: middle;
padding: 0 0.625em;
/*margin-left:1.25em;*/
list-style: none;
position: relative;
display: inline-table;
}
nav ul ul {
display:none;
}
nav ul ul li {
float:none;
position:relative;
color:#fff;
}
nav ul li:hover > ul {
display:block;
background:#fff;
}
nav ul ul ul {
position: absolute; left: 100%; top:0;
}
nav ul li a {
display: block; padding: 1em 2em;
color: #003c7d; text-decoration: none;
font-size:1.15em;
}
nav ul li a:hover {
color:#fff;
}
nav li:hover > a, nav li a.active {
color:#FFFFFF;
}
nav ul li a:active{
color:#fff;
}
nav ul li:hover {
background: #003c7d;
}
li {
float:left;
vertical-align:middle;
}
<nav>
<ul>
<li>MS-1</li>
<li>MS-2</li>
<li>MS-3</li>
<li>MS-4</li>
<li style="font-weight:bold">Competencies
<ul>
<li>Physician as Healer [A]
<ul>
<li>A1</li>
<li>A2</li>
<li>A3</li>
</ul>
<li>Physician as Scientist [B]
<ul>
<li>B1</li>
<li>B2</li>
<li>B3</li>
</ul>
<li>Physician as Advocate [C]
<ul>
<li>C1</li>
<li>C2</li>
<li>C3</li>
</ul>
<li>Physician as Educator [D]
<ul>
<li>D1</li>
<li>D2</li>
<li>D3</li>
</ul>
<li>Physician as Colleague [E]
<ul>
<li>E1</li>
<li>E2</li>
<li>E3</li>
</ul>
<li>Physician as Role Model [F]
<ul>
<li>F1</li>
<li>F2</li>
<li>F3</li>
</ul>
<li>Physician as Life-long Learner [G]
<ul>
<li>G1</li>
<li>G2</li>
<li>G3</li>
</ul>
</ul>
</li>
</ul>
</nav>
Related
here is the HTML:
http://codepen.io/anon/pen/epvNRG
<select>
<red>
</select>
.
^ is what i tried to use but it doesnt look as good! thanks
What I need:
A dropdown menu on hover. When cursor is on 'glossary' have a dropdown menu below glossary that can say anything! Thanks! Please make it the same size as the glossary box! Aparrt from that, a little transparancy would be cool too!
Thanks!
My suggestion to you would be to either learn some bootstrap becasue it makes a lot of the css coding and such a whole lot easier, or do a quick google search before asking on the form. Anyways:
html:
<html>
<head>
<meta charset="UTF-8">
<title>Watts</title>
<link rel="stylesheet" href="main.css" type="text/css">
</head>
<body>
<ul>
<li class="highlight">Home</li>
<li>References</li>
<li>Glossary</li>
<li>
Products ▾
<ul class="dropdown">
<li>Laptops</li>
<li>Monitors</li>
<li>Printers</li>
</ul>
</li>
</ul>
</div>
</body>
</html>
CSS:
body
{
margin: 0;
padding: 0;
background-color: #ccc;
} /* End of body rule */
ul
{
list-style: none;
background-color: #444; /* A very dark shade of grey as a background colour. */
text-align: center;
margin: 0;
padding: 0;
} /* End of ul rule */
li {
width: 120px;
border-bottom: none;
height: 50px;
line-height: 50px;
font-size: 1.4em;
display: inline-block;
} /* End of li rule */
a
{
color: #fff; /* A white colour. */
text-decoration: none;
display: block;
transition: 0.65s;
} /* End of a rule */
a:hover
{
background-color: #005f5f; /* rgb(0, 95, 95) - A colour similar to teal. */
} /* End of a:hover rule */
.highlight a /* Makes the block of the navigation page that you are on white on the navigation bar. */
{
background-color: #fff; /* A white background colour. */
cursor: default;
color: #444
} /* End of .highlight a rule */
ul{
padding: 0;
list-style: none;
background: #f2f2f2;
}
ul li{
display: inline-block;
position: relative;
line-height: 21px;
text-align: left;
}
ul li a{
display: block;
padding: 8px 25px;
color: #333;
text-decoration: none;
}
ul li a:hover{
color: #fff;
background: #939393;
}
ul li ul.dropdown{
min-width: 125px; /* Set width of the dropdown */
background: #f2f2f2;
display: none;
position: absolute;
z-index: 999;
left: 0;
}
ul li:hover ul.dropdown{
display: block; /* Display the dropdown */
}
ul li ul.dropdown li{
display: block;
}
You can try this pure HTML/CSS Menu:
*{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}:before,:after{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}
nav { width:100%; background:#000; display:inline-block;}
nav ul { margin:0; padding:0;}
nav ul li { margin:0; padding:0; list-style:none; display:inline-block; cursor:default;}
nav ul li a { color:#fff; padding:10px; font:15px 'Roboto', Arial, Helvetica, sans-serif; text-decoration:none; display:inline-block;}
nav > ul > li { float:left;}
nav ul li:hover > a { color:#fff; background:#005f5f;}
nav ul li a.active { color:#fff; background:#3b4747;}
nav ul ul { width:auto; min-width:200px; display:none; background:#131313; position:absolute; z-index:555; text-align:left;}
nav li:hover > ul { display:block;}
nav ul ul ul { left:100%; top:0;}
nav ul ul li { width:100%; display:block; float:none;}
nav ul ul a { width:100%; padding:8px 15px; display:block; color:#fff; border-bottom:1px solid #111;}
nav ul ul li:hover > a { background:#005f5f; color:#fff;}
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li><a>Services</a>
<ul>
<li>Sample Menu</li>
<li>Sample Menu</li>
<li>Sample Menu</li>
<li>Sample Menu</li>
</ul>
</li>
<li>Blog</li>
<li><a>Support</a>
<ul>
<li>Sample Menu</li>
<li>Sample Menu</li>
</ul>
</li>
<li>Contact Us</li>
</ul>
</nav>
I´m trying to make a submenu on hover for hours, read about ten tutorials or more and finally don't get it working.
I want it to show "Zimmer", "Reservierung" and "Preise" in a vertical menu if I hover "Hotel" and so on.
This is my code:
a {
text-decoration: none;}
nav {
height: 50px;
clear: both;}
nav ul {
padding: 5px 0px;
text-align: center;}
nav li {
margin: 0px;
display: inline;
padding: 0px;}
nav li a {
font-size: 18px;
color: #775923;
padding: 0px 20px;
margin: 0px;}
nav li a:hover, nav li a.current {
color: #775923;
padding: 0px 20px 14px 20px;
-webkit-padding-after: 15px;
box-shadow: 0 4px #b1d130;}
nav ul ul{
display: none;}
nav ul li:hover ul {
display: block;}
<nav>
<ul>
<li>Willkommen</li>
<li>Hotel</li>
<ul>
<li>Zimmer</li>
<li>Reservierung</li>
<li>Preise</li>
</ul>
<li>Restaurant</li>
<ul>
<li>Speisekarte</li>
<li>Anlässe</li>
</ul>
<li>Anfahrt</li>
<li>Kontakt</li>
<ul>
<li>Team</li>
<li>Über Uns</li>
</ul>
</ul>
</nav>
Link: http://jsfiddle.net/AuJeF/445/
Hope you can help.
Thank you
You have the problem on your markup,
change as following-
<li>Hotel
<ul>
<li>Zimmer</li>
<li>Reservierung</li>
<li>Preise</li>
</ul>
</li>
(this is a simple dropdown menu)
<nav>
<ul>
<li>Willkommen</li>
<li>Hotel
<ul>
<li>Zimmer</li>
<li>Reservierung</li>
<li>Preise</li>
</ul>
</li>
<li>Restaurant<ul>
<li>Speisekarte</li>
<li>Anlässe</li>
</ul>
</li>
</ul>
</nav>
css
nav
{
margin-top:15px
}
nav ul
{
list-style:none;
position:relative;
float:left;
margin:0;
padding:0
}
nav 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
}
nav ul li
{
position:relative;
float:left;
margin:0;
padding:0
}
nav ul li.current-menu-item
{
background:#ddd
}
nav ul li:hover
{
background:#f6f6f6
}
nav ul ul
{
display:none;
position:absolute;
top:100%;
left:0;
background:#fff;
padding:0
}
nav ul ul li
{
float:none;
width:200px
}
nav ul ul a
{
line-height:120%;
padding:10px 15px
}
nav ul ul ul
{
top:0;
left:100%
}
nav ul li:hover > ul
{
display:block
}
jsfiddle
the mistake in you html. ul > ul mast be insite li. But not outsideю
<li>Hotel
<ul>
<li>Zimmer</li>
<li>Reservierung</li>
<li>Preise</li>
</ul>
</li>
You're writing style - if ul inside li then ul display block. But inside li no ul it after him.
Will validator error, because tag ul inside >ul that's not true, there can be only >li
Think, I help U
Here I have my website: http://gyazo.com/56e069ebf8b5bd61ee30523886180b88
There are a number of issues with the nav bar.
1.You can see that the text or nav bar is not horizontally centered, as indicated by the hover (which is equal on top and bottom)
2.There is to much space in between the text, (and this spacing is the only way I've found works without the text moving around when highlighting or hovering.
So for 1. is there a way I can make the text or the nav bar (not sure what is the cause) centre so the hover looks more equal (horizontally)
For 2. Is there a way I can close the gap between the text, while still keeping the same padding settings, and so it doesn't move the text around when I use the hover function.
I've also added a jsfiddle if that helps: http://jsfiddle.net/d1a5eshs/
HTML FOR NAV BAR
<!--TOP NAV BAR SECTION-->
<div id="nav_bar">
<ul>
<li>HOME
</li>
<li>STATUS
</li>
<li>INFO
</li>
<li>GAMEMODES
<ul>
<li>SURVIVAL
</li>
<li><br>PURE-PVP
</li>
<li><br>GAMESWORLD
</li>
</ul>
</li>
<li>RULES
</li>
<li>VOTE
</li>
<li>CONTACT
</li>
</ul
CSS FOR NAV BAR
/*TOP NAV BAR SECTION*/
#nav_bar {
background-color: #a22b2f;
padding:1px;
box-shadow: 0px 2px
height:45px;
}
#nav_bar ul li {
display: inline-block;
}
#nav_bar ul li a {
color: white;
text-decoration:none;
font-weight:bold;
font-size:15px;
margin-left:10px;
padding-bottom:13px;
padding-top:17px;
padding-left:10px;
padding-right:10px;
margin-bottom:30px;
}
#nav_bar ul li ul {
display: none;
}
#nav_bar>ul>li>a:hover {
background:#8c1b1f;
padding-bottom:13px;
padding-top:13px;
padding-left:10px;
padding-right:10px;
}
#nav_bar>ul>li>ul>li>a:hover {
background:#c9c9c9;
padding-bottom:5px;
padding-top:5px;
padding-left:5px;
padding-right:5px;
}
#nav_bar ul li:hover ul {
display: block;
position: absolute;
padding: 0px;
background: #e2e2e2;
padding-top:10px;
padding-bottom:10px;
padding-left:0px;
padding-right:10px;
border: 1px solid black;
border-radius:5px;
}
#nav_bar ul li:hover ul li {
display: block;
}
#nav_bar ul li:hover ul li a {
color: black;
font-size:12px;
font-weight:bol;
margin-left:-20px;
padding-bottom:5px;
padding-top:5px;
padding-left:5px;
padding-right:5px;
}
There were several spacing issues and also there were several duplicate styles and a few mistakes, but I think I fixed all your issues. http://jsfiddle.net/d1a5eshs/1/.
Here's my version of your navigation bar: http://jsfiddle.net/zo541am2/. I trimmed and simplified both your HTML and CSS code.
HTML:
<nav>
<ul>
<li>HOME</li>
<li>STATUS</li>
<li>INFO</li>
<li>GAMEMODES
<ul>
<li>SURVIVAL</li>
<li>PURE-PVP</li>
<li>GAMESWORLD</li>
</ul>
</li>
<li>RULES</li>
<li>VOTE</li>
<li>CONTACT</li>
</ul>
</nav>
CSS:
* {
margin: 0;
padding: 0;
}
body {
padding: 10px;
}
nav {
background-color: #a22b2f;
box-shadow: 0px 2px 10px;
}
ul {
list-style-type: none;
}
nav > ul {
display: table;
margin: 0 auto;
min-width: 650px;
text-align: center;
}
nav > ul > li {
display: inline-block;
position: relative;
}
nav > ul > li > a {
display: block;
color: #fff;
text-decoration: none;
font: bold 15px/3 Serif;
padding: 0 15px;
}
nav ul ul {
display: none;
position: absolute;
min-width: 100%;
background: #e2e2e2;
border: 1px solid gray;
border-radius: 2px;
}
nav > ul > li:hover > a {
background: #8c1b1f;
}
nav ul ul li a {
display: block;
color: black;
font: bold 12px/3 Sans-Serif;
text-decoration: none;
}
nav ul ul > li:hover > a {
background: #c9c9c9;
}
nav > ul > li:hover > ul {
display: block;
}
I have an existing HTML menu which I need to add further navigation to. I have added in the extra <ul> and <li> tags which I believe are in the correct place. I also have some CSS but ti appears to mess up the links on the nav bar.
Here is an image of what it currently looks like:
http://gyazo.com/b45d1a07de57e617715b74ced91b942b
This is what it like before I added the code for the dropdown menu:
http://gyazo.com/d3dcd6b866187a650f83842beeb0be0d
HTML
<!--TOP NAV BAR SECTION-->
<div id="nav_bar">
<ul>
<li>HOME</li>
<li>STATUS</li>
<li>INFO</li>
<li>GAMEMODES
<ul>
<li>GAMEMODE - SURVIVAL</li>
<li>GAMEMODE - PURE-PVP</li> `enter code here`
<li>GAMEMODE - GAMESWORLD</li>
</ul>
</li>
<li>RULES</li>
<li>VOTE</li>
</ul>
</div>
CSS
#nav_bar {
background-color:#a22b2f;
padding-top:10px;
height:35px;
box-shadow: 0px 2px 10px;
}
#nav_bar ul {
margin:-15px;
margin-left:110px;
}
#nav_bar ul li {
display:inline;
}
#nav_bar ul li ul {
opacity:0;
}
#nav_bar ul li:hover ul {
opacity:1;
}
#nav_bar a:link {
text-decoration: none;
}
#nav_bar a:visited {
color:#ffffff;
}
#nav_bar a:hover {
background:#8c1b1f;
padding-bottom:12px;
padding-top:16px;
padding-left:10px;
padding-right:10px;
}
I had to completely remove your CSS with the exception of the styles which you had applied to #nav_bar and cleaned up your HTML structure as well by removing all the  's.
#nav_bar {
background-color: #a22b2f;
padding: 10px;
box-shadow: 0px 2px 10px;
}
#nav_bar ul {
text-align: center;
padding-left: 0px;
}
#nav_bar ul li {
display: inline-block;
}
#nav_bar ul li a {
color: white;
font-family: Arial;
text-decoration: none;
font-weight: bold;
padding: 15px;
}
#nav_bar ul li ul {
display: none;
}
#nav_bar ul li:hover ul {
display: block;
position: absolute;
padding: 0px;
background: white;
padding: 10px;
border: 1px solid black;
}
#nav_bar ul li:hover ul li {
display: block;
}
#nav_bar ul li:hover ul li a {
color: black;
}
<div id="nav_bar">
<ul>
<li>HOME
</li>
<li>STATUS
</li>
<li>INFO
</li>
<li>GAMEMODES
<ul>
<li>GAMEMODE - SURVIVAL
</li>
<li>GAMEMODE - PURE-PVP
</li>
<li>GAMEMODE - GAMESWORLD
</li>
</ul>
</li>
<li>RULES
</li>
<li>VOTE
</li>
</ul>
</div>
You can style it further as per your needs.
I have been trying to add a drop down menu to this code but always seem to get turned around. I just want a basic look to the subnav with a simple rollover effect. Every time i try different code it uses home image in the drop down menu and will not disappear when it is not hovered over. Ideas?
HTML:
<ul class="navbar">
<li class="navbar1">Home
<ul class="subnav">
<li>Menu 1 </li>
<li>Menu 2 </li>
</ul>
</li>
</ul>
CSS:
ul.navbar {
width:1000px;
list-style:none;
height:40px;
}
ul.navbar li {
display:inline;
}
ul.navbar li a {
height:40px;
float:left;
text-indent:-9999px;
}
/* Home 0 */
ul.navbar li.navbar1 a {
width:86px;
background:url(../pelican%20outfitters/navbar2.fw.png)
no-repeat 0 0;
}
ul.navbar li.navbar1 a:hover {
background-position:0 -40px;
}
ul.navbar li.navbar1 a.current {
background-position:0 -80px;
}
HTML
<nav>
<ul class="navbar">
<li class="navbar1">Home
<ul class="subnav">
<li>Menu 1
</li>
<li>Menu 2
</li>
</ul>
</li>
</ul>
</nav>
CSS
nav {
margin: 20px auto;
}
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
nav ul li
{
width:100px;
}
ul li ul li
{ width:200px;
}
nav ul {
font-size: 25px;
background: white;
padding: 0px;
border-radius: 10px;
border-style: solid;
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: black;
position:relative;
z-index:1;
}
nav ul li:hover a {
color: white;
position:relative;
z-index:1;
}
nav ul li a {
display: block;
padding: 15px 20px;
color: black;
text-decoration: none;
}
nav ul ul {
background: #000000;
border-radius: 0px 0px 10px 10px;
padding: 0;
position: absolute;
top: 100%;
}
nav ul ul li {
float: none;
}
nav ul ul li a {
padding: 15px 20px;
}
nav ul ul li a:hover {
background: #2E2E2E;
border-radius: 10px;
}
Output:
Working Fiddle
You should delete the text-indent:-9999px and add this to your css
Delete row:
ul.navbar li a { text-indent:-9999px }
Css:
.navbar li ul {display:none;}
.navbar li:hover ul {display:block;}
Than you have a basic navbar with hidden subnavs.
From here you can try it with your image.
The demo is your code with the new code..
DEMO
More like you want is, dont delete the css.. but only add those 2 lines and this 1:
.navbar li:hover li a{ text-indent:1px; background:white; }
DEMO 2 (without your img (don't know what it is)).
Latest update after the fiddle comment:
You should specify your html and css.. a just added a class to the first link class="home" and to accomodations class="accomodations"
And changed it in the css..
/* Home */
ul.navbar li.navbar1 a.home {
width:86px;
background:url(http://s12.postimg.org/rszejjscd/navbar2_fw.png)
no-repeat 0 0;
}
/* Accomodations */
ul.navbar li.navbar2 a.accomodations {
width:220px;
background: url(http://s12.postimg.org/rszejjscd/navbar2_fw.png) no-repeat -86px 0;
}
DEMO 3