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 5839263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:33:40+00:00 2026-05-22T11:33:40+00:00

I am trying to make a button, such that when the user clicks on

  • 0

I am trying to make a button, such that when the user clicks on it, it changes its style while the mouse button is being held down. I also want it to change its style in a similar way if it is touched in a mobile browser. The seemingly-obvious thing to me was to use the CSS :active pseudo-class, but that didn’t work. I tried :focus, and it didn’t work too. I tried :hover, and it seemed to work, but it kept the style after I took my finger off the button. All of these observations were on an iPhone 4 and a Droid 2.

Is there any way to replicate the effect on mobile browsers (iPhone, iPad, Android, and hopefully others)? For now, I am doing something like this:

<style type="text/css">
    #testButton {
        background: #dddddd;
    }
    #testButton:active, #testButton.active {
        background: #aaaaaa;
    }
</style>

...

<button type="button" id="testButton">test</button>

...

<script type='text/javascript' src='http://code.jquery.com/jquery-1.6.1.min.js'></script>
<script type='text/javascript'>
    $("*").live("touchstart", function() {
      $(this).addClass("active");
    }).live("touchend", function() {
      $(this).removeClass("active");
    });
</script>

The :active pseudo-class is for desktop browsers, and the active class is for touch browsers.

I am wondering if there is a simpler way to do it, without involving Javascript.

  • 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-05-22T11:33:40+00:00Added an answer on May 22, 2026 at 11:33 am

    There is no such thing as :touch in the W3C specifications, http://www.w3.org/TR/CSS2/selector.html#pseudo-class-selectors

    :active should work, I would think.

    Order on the :active/:hover pseudo class is important for it to function correctly.

    Here is a quote from that above link

    Interactive user agents sometimes change the rendering in response to user actions. CSS provides three pseudo-classes for common cases:

    • The :hover pseudo-class applies while the user designates an element
      (with some pointing device), but does
      not activate it. For example, a visual
      user agent could apply this
      pseudo-class when the cursor (mouse
      pointer) hovers over a box generated
      by the element. User agents not
      supporting interactive media do not
      have to support this pseudo-class.
      Some conforming user agents supporting
      interactive media may not be able to
      support this pseudo-class (e.g., a pen
      device).
    • The :active pseudo-class applies while an element is being activated by
      the user. For example, between the
      times the user presses the mouse
      button and releases it.
    • The :focus pseudo-class applies while an element has the focus
      (accepts keyboard events or other
      forms of text input).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a Button that will play a animation-list when pressed. I
I'm currently trying to make a button which will take the user back to
So I'm trying to make a button that launches the OpenFeint achievements page, but
I am trying to animate a button such that it grows to fill the
I want to make a button style on Android with two background colors, such
I'm trying to make a picture button in the compact framework. I made a
I am trying to make a form move (using the titlebar) from a button
I'm trying to make my site respond correctly to the back button. I've saved
Hey everyone. I'm trying to make a swing GUI with a button and a
Trying to make a make generic select control that I can dynamically add elements

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.