Css menu unclickable links - html

I built a little drop down menu without using any javascript, but it's not quite co-operating in firefox and IE 10. Here's what it looks like:
Both Link1 and Link2 are links. In chrome, clicking on them works fine - I get redirected as expected. In firefox and IE10, however, the menu just closes without visiting the link.
I thought it might be a z-index problem but I tried adding that and it didn't seem to do anything. Hovering over those links in firefox does bring up the tooltip showing the link address as well.
Any idea what might be causing this? Or is there a better way to do this? I'd like to try t avoid using javascript if possible.
Markup:
<ul class="header-right">
<li>
<ul class="user-menu">
<li class="menu-item" tabindex=0 id="submenu_li">
<span class="sub-menu-header" title="Menu">Long menu name Menu</span>
<div class="dropdown"></div>
<div class="user-sub-menu" id="user-sub-menu">
<ul class="submenu-list">
<li class="submenu-item">
<a id="a1" href="/Test">Link1</a>
</li>
<li class="submenu-item">
Link2
</li>
</ul>
</div>
</li>
</ul>
</li>
</ul>
Css is kind of long:
ul.header-right
{
position: absolute;
top: 7px;
right: 10px;
list-style-type: none;
margin: 0;
}
ul.header-right li
{
display: inline-block;
padding-left: 2px;
vertical-align: top;
}
li.menu-item
{
padding: 2px 2px 2px 10px !important;
}
li.menu-item:hover
{
background-color: #888888;
cursor: pointer;
}
li.menu-item:focus #user-sub-menu
{
display: block;
}
ul.user-sub-menu a, ul.user-sub-menu a:visited
{
text-decoration: none;
color: #232323;
}
div.user-sub-menu
{
display: none;
background-color: #FFFFFF;
min-width: 125px;
max-width: 300px;
min-height: 50px;
max-height: 400px;
position: absolute;
right: 22px;
z-index: 1000;
border: 1px solid #DDDDDD;
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
color: #232323;
font-size: 1em;
}
div.user-sub-menu ul
{
display: block;
margin: 0;
padding: 0;
}
div.user-sub-menu li
{
display: block;
padding: 2px 2px 2px 2px;
font-size: 1.15em;
border: 1px solid #FFFFFF;
}
div.user-sub-menu li a, div.user-sub-menu li a:visited
{
text-decoration: none;
color: #232323;
}
div.user-sub-menu li:hover
{
text-decoration: none;
background-color: #CCFFCC;
border: 1px solid #DDDDDD;
}
JSFiddle

I eventually figured out what was happening (or at least, I think I did).
When I focus li.menu-item the #user-sub-menu div appears as is all well and good. However, if I click on an element inside that div, such as one of the links, technically the li.menu-item element has lost the focus and makes the div invisible.
My best guess is that chrome processed the link click before it processed the focus change, and thus things worked right away. For firefox, I added the following css to keep the #user-sub-menu div open even when li.menu-item loses focus.
#user-sub-menu:active, #user-sub-menu:hover, #user-sub-menu:focus
{
display: block;
}
As a result this now works fine in Firefox. Unfortunately it still doesn't work in IE, so if anyone else has any insights there I'm happy to hear them, but I'll mark this as answered for now.

Related

Little space between ul border and li background

I have a little problem, there is a little problem on my menu, there is a little space between the ul border and the li background, here's my code:
Menu code:
.menu_base {
margin-left: auto;
margin-right: auto;
margin-top: 0;
list-style-type: none;
padding: 0;
overflow: hidden;
width: 75%;
border: 3px solid;
border-top: 0px solid;
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
border-color: #ff6eff;
}
.button {
float: left;
}
.button a {
padding: 15px 15px;
display: block;
text-align: center;
text-decoration: none;
color: #ff6eff;
font-family: sans-serif;
}
.button a:hover {
background-color: #ff6eff;
color: white;
}
<ul class="menu_base">
<li class="button">Accueil</li>
<li class="button" style="float: right">Inscription</li>
<li class="button" style="float: right">Connexion</li>
</ul>
Excepted result: (From Firefox)
https://i.stack.imgur.com/e62BM.png
Actual result: (From Chrome)
https://i.stack.imgur.com/x3wYU.png
Did you add the normalize CSS to the top op your CSS file?
All browsers sort of add their own style which can cause problems when adding CSS to your site. By normalizing the CSS you get the same margin, padding etc for all browsers. You can use Eric Meyers normalize CSS. Just copy the CSS from the link below and add it to the top of your CSS file.
You can find it here: https://meyerweb.com/eric/tools/css/reset/

css drop down nav bar for mobile works but is invisible on iphones

I coded this website entirely in HTML and CSS without using any libraries. The dropdown menu works perfectly fine on any computer or Android phone and I have tested in using multiple web browsers. On iPhones, the dropdown menu doesn't appear on the screen.
I thought it had to do with the issue of iPhone not supporting :hover, but after a lot of testing and attempts to fix it, I have found that the hover is not the problem. After clicking the nav, I have found that although not visible, the links in the dropdown menu work if I click on the correct place where it should be. Essentially, the dropdown menu and the links are there, but they can't be seen. I have tried adding visiblity: visible, z-index: 999 and several different display values but the problem persists.
nav {
position: relative;
background: white;
border: .05em solid #004EA8;
width: 100%;
}
nav .logo {
margin-bottom: .3em;
}
nav a {
color: white;
text-decoration: none;
display: block;
text-align: center;
}
nav ul,
nav:active ul {
list-style: none;
display: flex;
flex-direction: column;
position: fixed;
padding: 20px;
background: white;
top: 3.8em;
width: 100%;
}
.nav-sections {
display: none;
width: 100%;
}
.navbar-link {
display: flex;
flex-direction: column;
font-style: none;
text-decoration: none;
color: #004EA8;
}
.dropdown {
display: inline-block;
}
nav li,
.dropbtn {
background-color: white;
font: inherit;
text-align: center;
width: 100%;
padding: 5px 0;
margin: 0;
width: 100%;
}
.dropbtn a {
color: #004EA8;
}
nav:hover ul {
display: block;
}
.dropbtn {
display: flex;
flex-direction: column;
font-style: none;
color: white;
padding: 0;
}
.dropdown-content {
display: none;
}
.nav-button {
display: inline-block;
float: right;
color: white;
margin: .75em .6em .4em 1em;
}
.hamburger {
position: relative;
display: inline-block;
width: 1.25em;
height: 1.2em;
margin-top: .85em;
margin-right: 0.3em;
border-top: 0.2em solid #004EA8;
border-bottom: 0.2em solid #004EA8;
}
.hamburger:before {
content: "";
position: absolute;
top: 0.3em;
left: 0px;
width: 100%;
border-top: 0.2em solid #004EA8;
}
<nav class="nav">
<nav class="navbar-items items-left">
<img class="logo" src="images/NELS Logo 2145C.png" alt="New England Language School Building">
<div class="nav-button navbar-link navbar-link-toggle">
<div class="hamburger"></div>
</div>
<ul class="nav-sections">
<li class="single-line-link">Home</li>
<li class="single-line-link">About</li>
<li class="single-line-link">
<div class="dropdown navbar-link">
<button class="dropbtn">Languages</button>
<div class="dropdown-content">
English
French
German
Italian
Japanese
Mandarin
Portuguese
Spanish
Request a Language
</div>
</div>
</li>
<li class="single-line-link">Corporate</li>
<li class="double-line-link">Session<br>Dates</li>
<li class="single-line-link">Events</li>
<li class="double-line-link">Language<br>Partner</li>
<li class="single-line-link">Photos</li>
<li class="single-line-link">Location</li>
<li class="single-line-link">Policies</li>
<li class="single-line-link">Contact</li>
</ul>
</nav>
</nav>
Again, this is only an issue on iPhones. Any help would be hugely appreciated as I have spent hours/days searching for and trying different solutions that don't work.
I am including the code for the nav in HTML and the CSS to make the drop down menu work. To see the full code, you can visit the website at https://www.newenglandlanguage.com/
I have tested this on Safari and the behaviour of the menu shows the same issue as you have described. To fix it just remove the overflow: hidden property from the nav element selector in your media queries.

CSS Dropdown menu is waiting for a click on the item and then the hover works

My CSS Dropdown menu by hover is only working after the user clicks on the option, right after the click the dropdown shows and when hovering its acts perfectly,
I can't figure why it is happen and how to make the hover not wait for a click,
heres the html code:
<li>
events
<div class="nav-content">
<div class="nav-sub">
<ul>
<li>
weddings
<div class="underline"></div>
</li>
<li>
parties
<div class="underline"></div>
</li>
<li>
birthdays
<div class="underline"></div>
</li>
</ul>
</div>
</div>
</li>
heres the related css:
.nav-item {
display: inline-block;
padding: 20px, 30px;
height: 0px;
width: 130px;
color: black;
text-decoration: none;
border-color: black;
line-height: 40px;
}
.nav-content{
position: absolute;
background-color: white;
border-color: black;
color: #000000; font-family: "Varela Round";
font-size: 15px;
line-height: 24px;
text-align: right;
list-style-type: none;
z-index: 99999;
display: none;
left: 1110px;
}
.nav-sub{
padding: 1px;
border: 1px solid #000000;
position: relative;
z-index: 10;
}
.nav-sub ul li:hover {
background-color: black;
}
.nav-sub ul li:hover > .nav-item{
color: white;
}
.nav-item:focus{
background-color:whitesmoke;
}
.nav-item:hover ~ .nav-content{
display: block;
}
.nav-content:hover{
display: block;
}
Generally, your code here is pretty solid for a drop-down nav menu. It also works, as is, on jsFiddle. If it is not showing up until you click, some of your other code (not posted) is interfering. You might have to post the rest of your code in order to get help figuring out what is causing that behavior.
Note:
You will notice that positioning will be a chore unless you make a couple of changes. This is because positioning absolutely with relation to the window generally causes nothing but trouble.
/* Makes absolute children relative to the container */
li {
position: relative;
}
.nav-content {
...
left: 0;
...
}
The fiddle shows the changes, simply because it was otherwise causing inaccessible demonstration.

<li> element not clickable

I have this http://jsfiddle.net/wfhmtx8c/ so it works in jsfiddle?
#nav {
width: 100%;
float: left;
margin: 0 0 3em 0;
padding: 0;
opacity: 0.8;
list-style: none;
background-color: #f2f2f2;
border-bottom: 1px solid #ccc;
border-top: 1px solid #ccc; }
#nav li {
float: left; }
#nav li a {
display: block;
padding: 8px 15px;
text-decoration: none;
font-weight: bold;
color: #069;
border-right: 1px solid #ccc; }
#nav li a:hover {
color: #c00;
background-color: #fff;
border-bottom: black; }
<ul id="nav">
<li>Taal/Languague:</li>
<li>Nederlands</li>
<li>English</li>
</ul>
But when I put it on my website: http://ub3rhd.nl it doesn't work?
The code is really the same?
Your page is working perfectly fine for me. On hover, it changes color, and on click it redirects me to #.
Also, opacity on elements containing text is not exactly appealing. If i were you, i would get the opacity back at 100%. Language is spelled wrong, too. (: Good luck!
They seem to work, but the style isn't as the one in the jsfiddle.
Edit: They look fine now.
Also, as another user said, the transparency on the menu-bar doesn't look good. :)

How to make a multi-tiered dropdown menu with HTML and CSS only (maybe tiny JavaScript)

Newbie to CSS and can only find single level menus. Here's the Menu and the list items:
<ul>
<li>
Home
</li>
<li>
Forums
<ul>
Basketball
<ul>
<li>
Trading
</li>
<li>
Personal Collections
</li>
<li>
Box Breaks
</li>
</ul>
</ul>
</li>
</ul>
As you can see, it would be multi-tiered. Now, with the CSS I have, only Home and Forums are displayed first, and when I hover over Forums, Basketball is displayed...but so are the subsequent menu items. I want those to stay hidden until I hover over basketball. Anyone know how to do this with just CSS or as little JavaScript as possible? Thanks. Here's the CSS code I have:
ul
{
margin: 0;
padding: 0;
list-style: none;
width: 150px;
border-bottom: 1px solid #ccc;
}
ul li
{
position: relative;
}
li ul
{
position: absolute;
left: 149px;
top: 0;
display: none;
}
ul li a
{
display: block;
text-decoration: none;
color: #777;
background: #bad8f8;
padding: 2px 0 2px 10px;
border: 1px solid #ccc;
border-bottom: 0;
}
li:hover ul
{
display: block;
}
/* Styles for validation helpers
-----------------------------------------------------------*/
.field-validation-error
{
color: #ff0000;
}
.field-validation-valid
{
display: none;
}
.input-validation-error
{
border: 1px solid #ff0000;
background-color: #ffeeee;
}
.validation-summary-errors
{
font-weight: bold;
color: #ff0000;
}
.validation-summary-valid
{
display: none;
}
Here is a working demo:
http://jsfiddle.net/rcravens/aqz8q/
Two things I did.
A bit of restructuring the ul/li list. There were some elements not in the li.
Used 'li:hover > ul' to select the direct children only.
Hope that helps.
Bob
Try to add
ul li ul{position: absolute; top: 0; left: 0; width: 250px; height: 250px; background-color: #EEE;}
And go from there :)
The way you have structured your css causes all of "Basketball"'s descendants to inherit its css. You should be using a child(">") or :first-child selector instead. Look at sections 5.5 and 5.6 here to know what I am talking about: http://www.w3.org/TR/CSS2/selector.html
If you are looking to do dynamic menus I'd strongly recommend using javascript over relying purely on css, unless you are certain a lot of people viewing your website are going to have their javascript turned off.