Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7998953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:21:44+00:00 2026-06-04T15:21:44+00:00

So, I decided to start really learning CSS more in-depth, and I began by

  • 0

So, I decided to start really learning CSS more in-depth, and I began by attempting to implement a pure-CSS drop-down menu/select-box. I started by studying the code available in some online tutorials.

Ultimately, I came up with this, which I think is pretty decent. However, I’ve come to the conclusion that CSS menus might never be a suitable replacement for Javascript menus in all cases, because there are subtle problems that come up when you ditch Javascript.

If the items in your drop-down menu are simply <a href links, everything should be fine. BUT if you want each link to fire a Javascript event, you run into the following issues:

  • When the user clicks an item in the drop-down box, you want the
    drop-down box to disappear, obviously. This happens automatically
    if the items in your drop-down box are <a> elements. If they’re
    NOT <a> elements, the drop-down box won’t disappear on-click –
    which leaves you with two options: (A) wire up some Javascript that
    listens for onclick and then make the drop-down box disappear, or
    (B) use the css :active selector to set the drop-down box’s
    display property to none. (A) is stupid, because you’re
    basically back to Javascript menus at that point, and (B) doesn’t
    work out because it prevents Javascript events from firing when you
    click an item in the menu.

  • So, you have to use <a> tags. That means if you want to
    associate an event with a menu-item selection, you need to use an
    inline onclick in your <a> tag. That’s fine, except if you do
    that, it prevents the drop-down menu from disappearing (as
    demonstrated in my jsfiddle link
    ). So, really, CSS-only
    drop-down menus only seem to be workable if all you want to do when
    the user selects a menu item is navigate to another page via an <a>
    link. I can’t find any way to get a Javascript function to fire that
    doesn’t come with some gotcha.

Question: So, is what I’ve said accurate? Or is there a way to create a CSS-only drop-down menu that (A) disappears when the user clicks it, and (B) triggers a Javascript function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:21:45+00:00Added an answer on June 4, 2026 at 3:21 pm

    I think that you’re a bit confused. You seem to think that there is a binary that exists: either all CSS or all JS. This is a silly way to think. You should use CSS when it makes sense to use CSS and use JS to do things that CSS wasn’t made for. In most cases, using CSS to do the heavy lifting for you (hide/showing of menus, etc) and then enhancing said menu with additional functionality that CSS can’t provide is the way that most professional front end devs build menus.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to programming and stackoverflow and have decided to start by learning objective
I have decided (whether it's for better or for worse), to start learning the
A few days ago, I decided to start learning C#. So, I got a
Lately, I've decided to start using Perl::Critic more often on my code. After programming
I've decided to start running StyleCop on a medium sized project and am getting
So I decided to start using prototype and here's my first question. I'm trying
The software group I currently work in has recently decided to start documenting our
I wanted to learn C, so I decided to start a C project and
Over the weekend, for some reason, one of our servers has decided to start
So I've finally decided to update my PHP for the year 2012 by learning

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.