Jump to content

Responsive CSS only menu


jimleeder123

Recommended Posts

We've got a responsive menu that when you click on an li the ul inside it is then displayed as a block (displayed as none beforehand). However you cannot then close the ul without refreshing the page or closing the menu itself. 

 

What we want is for when you click the li again, the ul inside it then displays as none. Is this possible using only CSS? (No jQuery please!!!)

 

Any help is greatly appreciated, thanks!

Link to comment
Share on other sites

Its a menu in Wordpress, when you click the link and the sub menu appears, it pushes everything else down so that hack doesn't work. 

 

How it works is you click the li element which makes the ul element inside it appear.  The below code is 2 CSS styles I've got.

/* this makes the sub menu appear */
.responsivewrap ul li:hover ul.sub-menu {display:block !important;} 	
	
/* this is outdone by the above style. If set to important, sub menu won't appear (above style won't work) */
.responsivewrap ul li a:hover + ul[style*="display: block"] {display:none !important}

The first one makes it appear and was there before I started this exercise. The second style is what I've added in.

 

Since I have to use the same element to open AND close the ul element, the 2 styles override each other. The only thing I can think of to counter it is jQuery but we want to use CSS only.

Link to comment
Share on other sites

I can't see how any of that will be a help, I already know about the pointer-events property.

 

I think jQuery might be the only way since adding classes to open the ul and close it using the same link element causes the styles to cancel the other out.

 

However am open to any ideas for it to be done CSS only.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.