Configure Touch Screen Media Queries Using Tailwind CSS

October 10, 2022

Using Tailwind CSS For Touch Screen Media Queries

At the time of this writing I’m using Tailwind version 3.1.8. The issue I’m looking to deal with is detecting whether or not the device I’m targeting allows for ‘touch’ interactions. Specifically, I have a ‘group-hover’ class that returns the hover state on mobile… I don’t want that.

Here’s the code where the ‘group-hover’ class works on mobile devices. When the user touches the screen's interactive div element, the text will change from blue to red.

        
            <div id="card" class="group">
                <p class="text-blue-400 group-hover:text-red-400">
                  Here is placeholder text.
                </>
            </div>              
        
    

To resolve this issue I’ve configured my Tailwind.config.js with the following code:

        
            module.exports = {
                future: {
                  hoverOnlyWhenSupported: true,
                },
              }              
        
    

Tailwind has addressed the mobile hover issue and will officially release it in version 4.0. However, if you can’t wait until then simply add the bit of code above to your Tailwind config file and your hover states will only work on devices that support it.

Second CTA Ogilvy's Legacy

Today, David Ogilvy's influence can still be felt in the world of advertising.

Ogilvy's Influence Example
Emphasis on research Market research is a crucial part of any successful advertising campaign
Focus on headlines A strong headline can make the difference between an ad that is noticed and one that is ignored
Use of visuals Compelling images and graphics are essential for capturing audience attention