Change mobile menu colors on hover

Hi - I have a problem in that Paul said the parent of my dropdown menu (one child) must never be a live link, for mobile to display correctly. It links to a non-existent ID on the same page, like this:

<ul class="sf-menu">
    <li><a href="#gogreen">

It’s confusing, because people expect when they see the cursor-arrow turning into a finger, that if they click that, it’s a link. The only solution I can think of is to try get <li> not to light up.

The css was this:

.sf-menu li{background:#2aa048;}
.sf-menu li a:hover{background:#4cb15e;}

I tried changing it to this:

.sf-menu li{background:#2aa048;}
.sf-menu li a:hover{background:#2aa048;}

But that doesn’t work. Can you see what colors I need to change so the parent won’t light up but the child will, on hover?

The colors are this (dark, light, lighter): 2aa048,3ba953,4cb15e

and the css is – see http://greensmoothie.com

.sf-menu li{background:#2aa048;border-right:1px solid #3ba953;}
@media screen and (max-width:889px)
    {.sf-menu li{white-space:normal;}} /*wraps dropdwn txt in hamburger*/
.sf-menu > li:first-child{border-radius:8px 0 0 8px;}
.sf-menu > li:last-child{border-radius:0 8px 8px 0;border-right:none;}
.sf-menu li.end ul{left:auto;right:0;min-width:8em;}
.sf-menu li a:hover{background:#2aa048;}
.sf-menu ul li{background:#3ba953;}
.sf-menu li:hover,.sf-menu li.sfHover{background:#4cb15e;}
/* mobile nav menu */
.mobile-menu{display:none}
.mobile-menu{
    padding:1px 35px 1px 7px;
    margin:5px 0 0 0;
    background:#2aa048;
    font-weight:bold;
    cursor:pointer;    
    clear:both;
    text-align:center;
    line-height:49px;
    height:49px;
    color:#fff;
    z-index:999;
    border:1px solid #3ba953;
    border-radius: 4px;
    font-size:18px;
}

/* hamburger menu code */
.hamburger-menu {
  cursor: pointer;
  outline: none;
  width: 30px;
  height:24px;
  background:#2aa048;

thank you! - Val

I don’t see why it’s a problem that the menu headers highlight, although they are not a link, they are a clickable thing to open the sub-menu, so highlighting seems natural for them. Also, hover does not happen on touch screen, so mobile users won’t see it anyway.
But if you do want to change it, you will need more specific css selectors.
At present .sf-menu li a:hover targets all li links in the menu, you could be more specific to target only those in sub-menus.

.sf-menu li ul li a:hover {background:#4cb15e;}

I’m with Sam and the action of the top menu highlighting on hover is standard behaviour across all these drop down menus and I feel it would look awkward if the top menu doesn’t highlight because in a multi level menu its the highlighted item that provides the visual clue to the destination link.

You could just turn off the pointer for the top level.

e.g.

.sf-menu> li > a{cursor:default}

Thank you Paul - that works perfectly, taking away the finger-hover. My other problem is that the last two menu items on right “Blog” and “About” don’t work in mobile. They work fine on laptop.

I thought it was the google mobile checker that was at fault but now I’ve just tested it on my iphone and they definitely don’t work. If I try click the first child in “Blog” I get taken to the first page under the previous item “Water” and ditto when I click first child under “About” - I get taken to first page under “Blog”!

Well something like that, gets a bit confusing…

Find this rule in your media query near the end of the css:.

.sf-menu li > ul,
	.sf-menu li > ul  {
		display: block!important;
		left:-999em;
	}

Change it to this:

.sf-menu li > ul,
   .sf-menu li > ul,
   .sf-menu li.end > ul {
		display: block!important;
		left:-999em;
		right:auto;
	}

e.g. Full section code:

@media screen and (max-width:889px) {/*793*/
	.mobile-menu{display:block}
	.mobile-menu + #menu{display:none}
	.sf-menu li > ul,
	.sf-menu li > ul,
	.sf-menu li.end > ul {
		display: block!important;
		left:-999em;
		right:auto;
	}
	.sf-menu,.sf-menu li,.sf-menu li a{
		display:block;
		float:none;
		width:auto;	
	}
	.sf-menu ul {
		min-width:0;
		width:100%;
		opacity:0;
		-moz-transition:opacity .3s ease;
		-webkit-transition:opacity .3s ease;
		transition:opacity .3s ease;
	}
	.sf-menu li.mobileShow ul{
		left:0;
		top:0;
		position:relative;
		opacity:1;
		}
}

Thank you! That works! And showed me a new problem :slight_smile:

How do I get the cursor on parent to go back to a finger in mobile? It’s fine as an arrow in laptop because the dropdown auto-displays when you hover over it. But in mobile you have to click parent for child to display. As an arrow it doesn’t look like a clickable link.

Also I changed the width of the child in “Blog” and “About” way back when in the beginning of time, and I can’t recall which css line I changed it in. Can you see which it is? I’d like to delete that change since the children are all now longer than they were at the time.

On mobiles the cursor is always a finger: one attached to your hand, :hand: unless you use your nose! :nose:

2 Likes

haha you misunderstand. It’s a clickable finger on the children and I need that on the parent too :slight_smile: We just removed it from the parent.

Just add it back in that media query I just gave you.

@media screen and (max-width:889px) {
.sf-menu> li > a{cursor:pointer}
}

Thank you! That works! And do you perhaps see a line anywhere where I told the child of .end to be narrower than all the other children? I’d like to delete that command.

Not sure what you mean Val?

The dropdowns width is controlled by the length of text that it holds. It has a min-width of 12em but no max-width or width defined.

Hi Paul thank you! I found 12em here:

.sf-menu ul {min-width: 12em; /* allow long menu items to determine submenu width */
    *width: 12em; /* no auto sub width for IE7, see white-space comment below */
}

Is the 8em here perhaps what I’m looking to delete? I don’t know if the 8em is yours or mine and if mine, whether it refers to the same thing as .sf-menu ul?

.sf-menu li.end ul{left:auto;right:0;min-width:8em;}

Yes I didn’t notice the min-width:8em but you can safely remove it.

Thank you! Hope you eat lotsa fresh food and stay healthy & super-brainy 'till we meet again :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.