• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

remove :hover effect for mobile devices

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › remove :hover effect for mobile devices

This topic is: resolved

Tagged: remove :hover for touch devices

  • This topic has 6 replies, 2 voices, and was last updated 11 years, 1 month ago by awdesign.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • November 14, 2014 at 8:18 am #131494
    awdesign
    Member

    I have a:hover effect on primary navigation links to change color of the text. But I like to remove hover effect for mobile devices since you have to click twice on navigation links on iPhone etc.

    :hover works fine on desktop browsers, but fails to function on iOS touch devices … Any guidance is much appreciated.

    here is the code I have;
    /* Primary Navigation
    --------------------------------------------- */
    .nav-primary .wrap {
    border: none;
    }
    .nav-primary a:hover,
    .nav-primary .current-menu-item > a,
    .nav-primary .sub-menu a:hover,
    .nav-primary .sub-menu .current-menu-item > a:hover {
    color: #ed702b;
    text-decoration:none;
    }

    November 14, 2014 at 1:29 pm #131546
    CleanPageDom
    Participant

    Hi there

    I don't think you can target specific devices (such as phone, tablet etc) with CSS, but you can target devices of a certain width.

    Where have you added your code? Is it in the media queries at the bottom of style.css? You could target, say, devices of 600px wide or less and that should do it - for most phones, at least.

    Thanks
    Dom


    Let’s build a website together…

    November 14, 2014 at 1:48 pm #131549
    awdesign
    Member

    Thanks Dom, it is in CCS but not in media section. how can you have a:hover for desktop only and not for phone tablet touch devices in CSS ?

    November 14, 2014 at 1:55 pm #131552
    CleanPageDom
    Participant

    I'm not sure which theme you're using, so this may differ slightly, but in Frameowrk, near the bottom of style.css you'll see:

    /*
    Media Queries
    ---------------------------------------*/

    where all of the device-specific CSS needs to go. Way down at the bottom is:

    @media only screen and (max-width: 767px)

    This is where styling for smaller devices goes (767px is one px narrower than a portrait iPad). You could either put your phone -specific CSS in here, or, if you want to target smaller devices than that, create a new media query, say:

    @media only screen and (max-width: 599px) {  
    
    .nav-primary .wrap {
    border: none;
    }
    .nav-primary a:hover,
    .nav-primary .current-menu-item > a,
    .nav-primary .sub-menu a:hover,
    .nav-primary .sub-menu .current-menu-item > a:hover {
    color: #ed702b;
    text-decoration:none;
    }
    
    }

    Thanks
    Dom


    Let’s build a website together…

    November 14, 2014 at 3:29 pm #131568
    awdesign
    Member

    Thanks Dom, still the same problem. I added this code to style.css

    /* Primary Navigation for desktop
    --------------------------------------------- */
    .nav-primary .wrap {
    	border: none;
    }
    .nav-primary a:hover,
    .nav-primary .current-menu-item > a,
    .nav-primary .sub-menu a:hover,
    .nav-primary .sub-menu .current-menu-item > a:hover {
    	color: #ed702b;
    	text-decoration:none;
    }
    .nav-primary .sub-menu .current-menu-item > a {
    	color: #fff;
    }
    
    /*  remove hover effect from touch devices */	
    .site-header .current-menu-item > a,
    .site-header .sub-menu a:hover {
    .nav-primary .wrap {
    	border: none;
    	}
    	.nav-primary a,
    	.nav-primary .current-menu-item > a,
    	.nav-primary .sub-menu a,
    	.nav-primary .sub-menu .current-menu-item > a{
    	color: #ed702b;
    	text-decoration:none;
    }
    }

    still you have to tap twice on touch devices. I think it still gets the hover effect from desktop css code.
    On iphone you have to tap twice to activate the link (I think 1st. tap triggers :hover, 2nd. tap triggers link).

    I found this article about it but I do not know how to apply the best solution.
    http://stackoverflow.com/questions/2741816/is-it-possible-to-force-ignore-the-hover-pseudoclass-for-iphone-ipad-users

    Any other advice appreciated, thanks for your help.

    November 15, 2014 at 1:54 pm #131635
    CleanPageDom
    Participant

    OK, I see. Reading the SO post you linked to, I think this is the order of things. You're going to need to get into your functions.php file, so it'd be good to have ftp access in case you misplace a comma or something and get the white screen of death.

    What the commenter on SO seems to be saying is you need to add that script, add a class to <body> and then apply that CSS (although I'm a little unclear as to what he means with the CSS comment). If I understand correctly, this is how I would go about it, but I am a little hazy on adding javascript.

    1. Via ftp, go to your child theme folder and create a folder named "lib", then, inside this, create another folder called "js" (this is not essential, but a couple of things I read about inserting other bits of javascript suggest this is a way to keep things neat).

    2. Open Notepad or similar and copy this in, save it as something like "nohover.js" and upload it to the js folder you created:

    if ('ontouchstart' in document) {
        Y.one('body').removeClass('no-touch');
    }

    3. Referencing this, and butchering it a little , enqueue your nohover.js by adding this to your functions.php:

    // Register no hover script
    add_action( 'wp_enqueue_scripts', 'PREFIX_enqueue_scripts' );
    function PREFIX_enqueue_scripts() {
     
    	wp_enqueue_script( 'PREFIX-responsive-menu', get_stylesheet_directory_uri() . '/lib/js/nohover.js', array( 'jquery' ), '1.0.0', true ); //change PREFIX to the name of your child theme
     
    }

    (3a - Just a note on this; I believe you could add: <script type="text/javascript" src="/lib/js/nohover.js"></script> into your <head> through Genesis > Theme Options.)

    4. Add a class to <body>, as explained here, in functions.php:

    //* Add custom body class to the head
    add_filter( 'body_class', 'sp_body_class' );
    function sp_body_class( $classes ) {
    	
    	$classes[] = 'no-touch';
    	return $classes;
    	
    }

    5. Now the final part, which I'm not 100% clear on, is adding the CSS he mentions:

    .no-touch my:hover{
       color: red;
    }

    I think he means to add that above any instance of an a:hover command that you want to overrule (so in .entry a, for example) but I'm not sure.

    I hope this sets you on the right path. Don't know how familiar you are with functions.php, but it can be pretty terrifying when you hit save and the screen goes white. Just go in to the file via ftp and remove the code you just added (or double check it to see if I missed out something). Might be an idea to copy your working functions.php somewhere so you can restore the original if necessary.

    Good luck.

    Thanks
    Dom


    Let’s build a website together…

    November 25, 2014 at 2:51 pm #132800
    awdesign
    Member

    Thanks Dom, appreciate your help,
    Lewis

  • Author
    Posts
Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘remove :hover effect for mobile devices’ is closed to new replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble