Dropdownmenu: Only words clickable not whole box - html

I've got a dropdownmenu for my site and I noticed only the words itself are clickable not the whole box the word (link) is placed in.
I already added display: block; to the a element but this seems to only work horizontal, still not the whole box.
Hope you can help me out! And Thank you in advance!
Here's de css code:
#dropdownmenu a {
color:inherit !important;
display:block;
text-decoration:none !important}
#dropdownmenu {
width:1050px;
background:#137cd7;
z-index:2;
position:relative }
#dropdownmenu ul {
text-align:left;
display:inline;
margin:0px;
padding:10px 4px 25px 0;
list-style:none }
#dropdownmenu ul li {
display:inline-block;
margin-right:10px;
position:relative;
padding:15px 15px 14px;
cursor:pointer;
-webkit-transition:all 0.2s;
-moz-transition:all 0.2s;
-ms-transition:all 0.2s;
-o-transition:all 0.2s;
transition:all 0.2s;
color:#fff }
#dropdownmenu ul li:hover {
background-color:#ffffff;
color:#137cd7 }
#media screen and (-webkit-min-device-pixel-ratio:0)
#dropdownmenu ul li ul {
top:44px !important}
#dropdownmenu ul li ul {
padding:0px;
position:absolute;
top:47px;
left:0px;
width:170px;
display:none;
opacity:0;
visibility:hidden;
-webkit-transiton:opacity 0.2s;
-moz-transition:opacity 0.2s;
-ms-transition:opacity 0.2s;
-o-transition:opacity 0.2s;
-transition:opacity 0.2s }
#dropdownmenu ul li ul li {
background-color:#fff;
display:block;
color:#222;
border-left:1px solid #ccc;
border-right:1px solid #ccc;}
#dropdownmenu ul li ul li:hover {
color:#137cd7;
background:#222;
text-decoration:none !important }
#dropdownmenu ul li:hover ul {
display:block;
opacity:1;
visibility:visible;
border-bottom:1px solid #ccc; }
And HTML:
<div id="dropdownmenu">
<ul>
<li>
Home</li>
<li>
Menu 1
<ul>
<li>
Submenu</li>
<li>
Submenu</li>
<li>
Submenu</li>
<li>
Submenu</li>
<li>
Submenu</li>
<li>
Submenu</li>
<li>
Submenu</li>
</ul>
</li>
<li>
Menu 2
<ul>
<li>
Submenu</li>
<li>
Submenu</li>
<li>
Submenu</li>
<li>
Submenu</li>
<li>
Submenu</li>
<li>
Submenu</li>
<li>
Submenu</li>
</ul>
</li>
<li>
Contact
<ul>
<li>
<img alt="" src="/files/19731/editor/images/support(1).JPG" style="width: 140px; height: 140px; border-width: 0px; border-style: solid;" /></li>
<li>
</li>
</ul>
</li>
</ul>
fiddle here
Thanks everyone!
Thank you for the answer! This helped me a lot! Everything works excellent now!

On the image below, you can see your dropdown's anchor in blue, and your li padding in green.
When you click on the green area, the browser will not follow the anchor which is a normal behaviour.
To correct that, remove the li padding, and apply it to the anchor. As anchors are inline elements, you'll have to display them as block to apply padding.
#dropdownmenu a {
padding:15px 15px 14px;
display: block;
}
I also have done some CSS improvements, you can take a look on the updated Fiddle

Related

Menu dropdown transition won't work (CSS only)

Can someone please help me do dropdown transition here... ?
On hover the dropdown should show up in fade-in manner. This is really confusing because right transition is not working no matter where I apply it. This colorful menu is just an example to get the right idea on how to make the dropdown transition work. I just need a simple ease-in transition that will work. I have been trying hard to fix this. Help is greatly appreciated.
<ul id='nav'>
<li class='menuitem1'>mainmenu1
<ul>
<li class='menuitem1'>Menu 111</li>
<li class='menuitem1'>Menu 22</li>
<li class='menuitem1'>Menu 3333</li>
<li class='menuitem1'>Menu 44
</li>
</ul>
</li>
<li class='menuitem2'>Menu3774
<ul>
<li class='menuitem2'>Menu 111</li>
<li class='menuitem2'>Menu 22</li>
<li class='menuitem2'>Menu 3333</li>
<li class='menuitem2'>Menu 44
</li>
</ul>
</li>
<li class='menuitem3'>Menury
</li>
</ul>
</nav>
<style>
.menuitem1 {
background:#4dd2ff;
}
.menuitem1:hover {
color:#000;
background:#94e4ff;
}
.menuitem2 {
background:#1aff8c;
}
.menuitem2:hover {
background:#87ffc3;
}
.menuitem3 {
background:#d2a679;
}
.menuitem3:hover {
background:#f5c89a;
}
nav > ul {
transition-duration: 0.5s;
}
#nav {
display:table;
margin:0;
}
#nav > li {
cursor:pointer;
list-style:none;
padding:12px 0;
border:1px #959696 solid;
position:relative;
display:table-cell;
width:1%;
text-align:center;
}
#nav ul li {
width: 250px;
display:block;
padding:3px 20px;
text-indent:0;
line-height:40px;
text-align:left;
border-top:1px #fff solid;
border-bottom:1px #fff solid;
border-left:none;
border-right:none;
position:relative;
}
#nav ul {
visibility:hidden;
opacity:0;
max-height:300px;
position:absolute;
filter:alpha(opacity=0);
transition: height 0.3s ease-in;
}
#nav li:hover > ul {
visibility:visible;
opacity:1;
filter:alpha(opacity=100);
}
ul {
display:none;
}
li:hover > ul {
display:block;
position:absolute;
z-index:1000;
border:1px #fff solid;
margin-top:12px;
margin-left:0;
}
#nav > li ul li ul {
left:100%;
top:-2px;
white-space:nowrap;
}
#nav li:hover > a, #nav li:hover {
}
li, li a {
color:#000;
text-decoration:none;
}
* {box-sizing:border-box;-moz-box-sizing:border-box;}
</style>
The transition becomes broken by the conflicting #nav styles you have for the menu. Creating class names is generally a recommended practice. I would reference the following example written on CodePen: https://codepen.io/shshaw/pen/gsFch
<nav>
<ul>
<li class="sub-menu-parent" tab-index="0">
Menu Item 1
<ul class="sub-menu">
<li>Sub Item 1</li>
<li>Sub Item 2</li>
<li>Sub Item 3</li>
<li>Sub Item 4</li>
</ul>
</li>
<li class="sub-menu-parent" tab-index="0">
Menu Item 2
<ul class="sub-menu">
<li>Sub Item 1</li>
<li>Sub Item 2</li>
<li>Sub Item 3</li>
<li>Sub Item 4</li>
<li>Sub Item 5</li>
<li>Sub Item 6</li>
</ul>
</li>
<li class="sub-menu-parent" tab-index="0">
Menu Item 3
<ul class="sub-menu">
<li>Sub Item 1</li>
<li>Sub Item 2</li>
</ul></li>
</ul>
</nav>
<style>
.sub-menu-parent { position: relative; }
.sub-menu {
visibility: hidden; /* hides sub-menu */
opacity: 0;
position: absolute;
top: 100%;
left: 0;
width: 100%;
transform: translateY(-2em);
z-index: -1;
transition: all 0.3s ease-in-out 0s, visibility 0s linear 0.3s, z-index 0s linear 0.01s;
}
.sub-menu-parent:focus .sub-menu,
.sub-menu-parent:focus-within .sub-menu,
.sub-menu-parent:hover .sub-menu {
visibility: visible; /* shows sub-menu */
opacity: 1;
z-index: 1;
transform: translateY(0%);
transition-delay: 0s, 0s, 0.3s; /* this removes the transition delay so the menu will be visible while the other styles transition */
}
/* presentational */
body { padding: 2%; font: 18px/1.4 sans-serif; }
nav a { color: #E00; display: block; padding: 0.5em 1em; text-decoration: none; }
nav a:hover { color: #F55; }
nav ul,
nav ul li { list-style-type: none; padding: 0; margin: 0; }
nav > ul { background: #EEE; text-align: center; }
nav > ul > li { display: inline-block; border-left: solid 1px #aaa; }
nav > ul > li:first-child { border-left: none; }
.sub-menu {
background: #DDD;
}
</style>
The action you want to do is css animation. Animation duration "animation-duration: 4s;" You can adjust it according to you. You can edit the transitions you want to do with "#keyframes example". For more information you can check here. https://www.w3schools.com/css/css3_animations.asp
.menuitem1 {
background:#4dd2ff;
}
.menuitem1:hover {
color:#000;
background:#94e4ff;
}
.menuitem2 {
background:#1aff8c;
}
.menuitem2:hover {
background:#87ffc3;
}
.menuitem3 {
background:#d2a679;
}
.menuitem3:hover {
background:#f5c89a;
}
nav > ul {
transition-duration: 0.5s;
}
#nav {
display:table;
margin:0;
}
#nav > li {
cursor:pointer;
list-style:none;
padding:12px 0;
border:1px #959696 solid;
position:relative;
display:table-cell;
width:1%;
text-align:center;
}
#nav ul li {
animation-name: example;
animation-duration: 4s;
width: 250px;
display:block;
padding:3px 20px;
text-indent:0;
line-height:40px;
text-align:left;
border-top:1px #fff solid;
border-bottom:1px #fff solid;
border-left:none;
border-right:none;
position:relative;
}
#keyframes example {
from {background-color: #94e4ff00;}
to {background-color: #94e4ff;}
from {color: #94e4ff00;}
to {color: black;}
}
#nav ul {
visibility:hidden;
opacity:0;
max-height:300px;
position:absolute;
filter:alpha(opacity=0);
transition: height 0.3s ease-in;
}
#nav li:hover > ul {
visibility:visible;
opacity:1;
filter:alpha(opacity=100);
}
ul {
display:none;
}
li:hover > ul {
display:block;
position:absolute;
z-index:1000;
border:1px #fff solid;
margin-top:12px;
margin-left:0;
}
#nav > li ul li ul {
left:100%;
top:-2px;
white-space:nowrap;
}
#nav li:hover > a, #nav li:hover {
}
li, li a {
color:#000;
text-decoration:none;
}
* {box-sizing:border-box;-moz-box-sizing:border-box;}
<ul id='nav'>
<li class='menuitem1'>mainmenu1
<ul>
<li class='menuitem1'>Menu 111</li>
<li class='menuitem1'>Menu 22</li>
<li class='menuitem1'>Menu 3333</li>
<li class='menuitem1'>Menu 44
</li>
</ul>
</li>
<li class='menuitem2'>Menu3774
<ul>
<li class='menuitem2'>Menu 111</li>
<li class='menuitem2'>Menu 22</li>
<li class='menuitem2'>Menu 3333</li>
<li class='menuitem2'>Menu 44
</li>
</ul>
</li>
<li class='menuitem3'>Menury
</li>
</ul>
</nav>

Menu Icon does not appear and links don't work

Im quite new to web design and am having trouble figuring out why my mobile dropdown menu works fine testing on a browser window, but when accessed using a mobile phone the black triangle denoting the 2nd list disappears and none of the links work; nothing happens when I touch them.
I've commented out the 'display:none' on the '#nav ul' selector so you can see how the menu functions, usually this would be uncommented.
Really appreciate any feedback, thanks.
<div id="nav">
<img id="menubtn" src="images/menuIcon.png" alt="Menu button" />
<ul>
<li>Home</li>
<li>Option 1 ▾
<ul>
<li>Option 1.1</li>
<li id="bottomSub">Option 1.2</li>
</ul>
</li>
<li>Option 2</li>
<li>Option 3</li>
<li>Option 4</li>
<li>Option 5</li>
<li id="bottomNav">Option 6</li>
</ul>
</div>
/*--- All style--- */
body{
background-color:lightblue;
}
#nav{
font-family:sans-serif;
z-index:1;
}
#nav a{
color:black;
}
#nav ul li{
list-style:none;
color:black;
}
#nav li:hover ul{
position:absolute;
visibility:visible;
display:block;
}
#nav a:hover{
color:yellow;
}
#nav ul li a{
text-decoration:none;
}
#nav ul ul{
position:relative;
display:none;
}
/* ----Mobile only---- */
#media screen and (max-width:480px){
#menubtn:hover + ul,#menubtn:focus + ul{
display:block;
}
#nav ul {
position:fixed;
top:95px;
background-color:#E5E5E5;
font-size:0.8em;
margin:0;
padding:0;
width:120px;
z-index:1;
/*display:none;*/
}
#nav ul li{
border-left:1px solid black;
border-right:1px solid black;
border-top:1px solid black;
padding:0;
padding:10px 4px;
}
#nav li:hover ul,#nav li:focus ul{
top:50px;
left:119px;
}
#nav ul ul li{
font-size:1.2em;
border-top: 1px solid black;
border-left: 1px solid black;
border-right: 1px solid black;
background-color:#E5E5E5;
padding:10px 4px;
width:130px;
}
#bottomSub, #bottomNav{
border-bottom: 1px solid black;
}
}
try by adding <a> tag on parent
<li>Option 1 ▾
<ul>
<li>Option 1.1</li>
<li id="bottomSub">Option 1.2</li>
</ul>
</li>
and display block to <a>
#nav ul li a {
display:block;
}
If you give padding and other style to <a> tag it would be better because :focus doesn't work on li tag.
Not tested but might solve your problem

IE10 stopping menu from working correctly

Please see a menu I'm using on a site below. It works fine in most browsers but with IE10 (IE11 is fine) when you hover over a menu item then go to select a sub menu item, when the cursor goes into any of the small gaps between the vertical sub menu items the menu thinks the user has went outside the submenu and it closes.
Can anybody tell me what is causing this to happen in IE10 and nothing else?
Regards,
Marc
#nav-wrap {
height:28px;
position:relative;
top:-70px;
width:100%;
margin:0 auto;
z-index:10;
text-align:center;
}
#nav {
font-size:15px;
font-weight:400;
text-align:center;
position:relative;
display:inline-table;
}
#nav ul li:hover > ul {
display:block;
}
#nav ul {
padding:0px;
margin:0px;
list-style:none;
position:relative;
}
#nav ul:after {
content:"";
clear:both;
display:block;
}
#nav ul li { /* KEY - Changes main nav bar li style */
float:left;
margin-left:14px;
margin-right:14px;
}
#nav ul li a {
display:block;
color:white;
text-decoration:none;
background:#416b8f;
border-radius:2px;
padding:3px 15px 3px 15px;
}
#nav ul li a:hover {
background:#003768;
border-radius:0px;
-webkit-transition: ease-in 0.2s;
-moz-transition: ease-in 0.2s;
-o-transition: ease-in 0.2s;
transition: ease-in 0.2s;
}
.selected {
background:#003768;
display:block;
color:white;
text-decoration:none;
border-radius:2px;
padding:3px 15px 3px 15px;
}
#nav ul ul {
position:absolute;
top:100%;
text-align:left;
margin:0;
display:none;
}
#nav ul ul li {
float:none;
position:relative;
margin:0px;
font-size:14px;
padding-top:1px;
padding-bottom:1px;
padding-left:2px;
}
#nav ul ul li:hover {
}
#nav ul ul li a {
border-radius:0px;
padding-top:5px;
padding-bottom:5px;
}
#nav ul ul li a:hover {
background:#003768;
-webkit-transition: ease-in 0.2s;
-moz-transition: ease-in 0.2s;
-o-transition: ease-in 0.2s;
transition: ease-in 0.2s;
}
#nav ul ul ul {
position:absolute;
left:100%; /* switch to left to change position of nested menus */
top:0;
}
li {
white-space: nowrap;
}
<div id="nav">
<ul>
<li>HOME</li>
<li>ABOUT
<ul>
<li>ACET
<ul>
<li>ACET HELPS</li>
<li>ACCREDITATION</li>
</ul>
</li>
<li>FEATURES</li>
<li>WEB DASHBOARD</li>
<li>ACET 8</li>
<li>CLIENTS</li>
<li class="selected">NEWS</li>
</ul>
</li>
<li>SERVICES
<ul>
<li>TRAINING</li>
<li>SUPPORT
<ul>
<li>HELP DESK</li>
<li>USER GUIDE</li>
<li>ACET TECHNICAL PRACTICE</li>
</ul>
</li>
<li>DATA IMPORT</li>
<li>DEVELOPMENT</li>
</ul>
</li>
<li>ASSET INTEGRITY
<ul>
<li>INTEGRITY INFORMATION</li>
<li>INSPECTION & INTEGRITY MANAGEMENT</li>
<li>NON-DESTRUCTIVE TESTING
<ul>
<li>SPECIALIST INSPECTION SERVICES</li>
<li>INSPECTION METHOD CAPABILITY</li>
<li>INSPECTION METHOD SELECTION</li>
</ul>
</li>
<li>DATA SOLUTIONS</li>
</ul>
</li>
<li>DOWNLOADS
<ul>
<li>LATEST NEWSLETTER</li>
<li>ACET DATA SHEET</li>
<li>ASSET INTEGRITY BROCHURE</li>
<li>THE INSPECTION STANDARD
</li>
</ul>
</li>
</ul>
</div>

Inline sub-lists width transition

Basically I want the list to have its sub-list displayed next to it, and the other list elements move aside nicely (transition) but if i set overflow it vertically aligns the sublist and if i set display: none then transitions don't work at all.
I just want the list to work like
Test Test Test
Then on hover with the first test and it pushes the last two tests aside smoothly and ends up
Test Test2 Test3 Test Test
I've tried searching and applying methods from other threads, but I can't find anything that will fit it, and work in IE nicely. I don't care for the transition to be working in IE, just that the list works.
http://jsfiddle.net/qohw1dxj/
<ul>
<li>
Test
<ul>
<li>Test2</li>
<li>Test3</li>
</ul>
</li>
<li>
Test
<ul>
<li>Test2</li>
<li>Test3</li>
</ul>
</li>
<li>
Test
<ul>
<li>Test2</li>
<li>Test3</li>
</ul>
</li>
</ul>
* {
padding: 0;
margin: 0;
-webkit-transiton: all 0.3s;
-moz-transition: all 0.3s;
-ms-transition: all 0.3s;
-o-transition: all 0.3s;
transition: all 0.3s;
}
ul {
list-style: none;
}
ul li {
display: inline-block;
}
ul li:hover ul {
max-width: 10000px;
max-height: 10000px;
}
ul li ul {
display: inline-block;
max-width: 0px;
max-height: 0px;
padding: 0;
list-style: none;
}
Did you mean something like this:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style>
* {
padding: 0;
margin: 0;
}
ul {
list-style:none;
white-space:nowrap;
}
ul li {
display: inline-block;
}
ul li a {
background:red;
padding:10px;
display:inline-block;
}
.menu > li > a {
position:relative
}
ul li li a {
color:red;
background:green
}
ul li ul {
display: inline-block;
width:0;
height:0;
max-width:0;
visibility:hidden;
}
ul li:hover ul {
margin-left:0;
width:auto;
height:auto;
opacity:1;
max-width:1000px;
visibility:visible;
-webkit-transiton: all 1s;
-moz-transition: all 1s;
-ms-transition: all 1s;
-o-transition: all 1s;
transition: all 1s;
}
</style>
</head>
<body>
<ul class="menu">
<li> Test A
<ul>
<li>Test2</li>
<li>Test3</li>
</ul>
</li>
<li> Test B
<ul>
<li>Test2</li>
<li>Test3</li>
</ul>
</li>
<li> Test C
<ul>
<li>Test2</li>
<li>Test3</li>
</ul>
</li>
</ul>
</body>
</html>
The transition rule cannot be applied to display style in CSS. This may be a solution you can try out:
Transitions on the display: property

submenus in css/html

I have got a submenu which expands from a nav menu type object when I hover over it. Right now, my main nav menu looks like so...
<div id= "navbar">
<ul>
<li><a href= "#" class= "navlink" id= "first"> First
<div class= "firstsubmenu">
<ul>
<li> <a href= "#" class="firstsubmenulink"> First sub menu option </li>
<li> <a href= "#" class="firstsubmenulink"> Second sub menu option </li>
etc...
</ul>
</div></a></li>
<li><a href= "#" class= "navlink" id="second"> Second
<div class= "secondsubmenu">
<ul>
..and so on
</ul>
</div>
Right now, my css is looking like
ul
{
list-style-type:none;
margin:0;
padding:0;
overflow:hidden;
}
li
{
float:left;
}
.navlink:link
{
display:block;
width:120px;
text-align:center;
padding:10px;
text-decoration:none;
color:#FFFFFF;
}
.navlink:hover
{
background-color:#ADD8E6;
color:#FFFFFF;
}
.navlink:visited
{
background-color:#ADD8E6;
color:#FFFFFF;
}
Before I tried making each item in the submenu a clickable link, everything showed up perfectly fine. IE: firstsubmenu showed up perfectly. It's css is
.firstsubmenu
{
display : none;
position : absolute;
left : 75px;
top : 32px ;
background-color : red;
width : 930px;
height : 25px;
z-index : 10;
}
But now that I added the links (made every list element within an block), firstsubmenu no longer appears.
The css for each link looked something like this
.firstsubmenulink
{
display:block;
width:120px;
text-align:center;
padding:10px;
text-decoration:none;
color:#FFFFFF;
}
But as I said, the submenu no longer even appears. I realize this is a bit of a long post, but any advice would be great.
You can use the below css and create pure css based menu.
Css:
body { padding: 3em; }
#navbar * { padding:0; margin: 0; font: 1em arial; }
#navbar { position: absolute; z-index: 99; margin: 0 auto; float: left; line-height: 20px; }
#navbar a { display: block; border: 1px solid #fff; background: #EFBE37; text-decoration: none; padding: 3px 10px; color:#666666; }
#navbar a:hover { background: #C6991D; }
#navbar ul li, #navbar ul li ul li { width: 120px; list-style-type:none; }
#navbar ul li { float: left; width: 120px; }
#navbar ul li ul, #navbar:hover ul li ul, #navbar:hover ul li:hover ul li ul{
display:none;
list-style-type:none;
width: 120px;
}
#navbar:hover ul, #navbar:hover ul li:hover ul, #navbar:hover ul li:hover ul li:hover ul {
display:block;
}
#navbar:hover ul li:hover ul li:hover ul {
position: absolute;
margin-left: 120px;
margin-top: -20px;
}
Structure:
<div id="navbar">
<ul>
<li>Home</li>
<li>Abous Us »
<ul>
<li>About us 1</li>
<li>About us 2 »
<ul>
<li>XXX
<li>XXX
<li>XXX
</ul>
</li>
</ul>
</li>
<li>Download</li>
<li>Menus »
<ul>
<li>Menus 1</li>
<li>Menus 2 »
<ul>
<li>Menus 2-1
<li>Menus 2-2
<li>Menus 2-3
</ul>
</li>
</ul>
</li>
<li>Contact</li>
<li>Feedback</li>
</ul>
jsBin live demo
I had to fix lot of errors in your HTML. Here is the css:
#navbar ul{
list-style:none;
margin:0; padding:0;
display:table;
}
#navbar li{
top:0px;
background:#bbf;
display:inline-block;
width:100px;
}
#navbar li ul li{
display:none;
}
#navbar li:hover li{
display:block;
}
And the fixed HTML:
<div id="navbar">
<ul>
<li>
First
<ul class="firstsubmenu">
<li>1. option</li>
<li>2. option</li>
</ul>
</li>
<li>
Second
<ul class="secondsubmenu">
<li>1. option</li>
<li>2. option</li>
</ul>
</li>
</ul>
</div>
Now, after it works, do with colors whatever you want.
Use also alt tags in your links and images, it improves your SEO and compilance.