What's the best way to implement the Tailwind hover media query alongside group-hover?

I have attempted to include "group-hover" in the P tag to make the red text hover on devices with hover capability, but I have not achieved success. The basic code structure for my issue is as follows...

<div id="card" class="group">
 <p class="text-blue-400 [@media(hover:hover){&:hover}]:text-red-400">
 Here is placeholder text.
 </p>
</div>

Is there a way to utilize "group-hover" so that the red text can appear during the hover state on devices that support hover actions?

Answer №1

<div id="card" class="group">
  <p class="text-blue-400 group-hover:text-red-400">
    This is sample text to fill the space.
  </p>
</div>

For more details, check out: Tailwind CSS Handling Hover

Latest Update

Note that Tailwind 3.1+ is necessary for using inline media queries

You have three options:

1. Allow future flag

Starting from version 4, the desired behavior will be default, but you can enable it in advance:

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

2. Inline

This method is a bit tricky as inline media query with whitespace cannot be used, so you might need to resort to group-hover (since

[@media(hover:hover){.group:hover}]:text-red-400
will not work in all cases); version 3.1+ required:

<div id="card" class="group">
  <p class="text-blue-400 group-hover:[@media(hover:hover)]:text-red-400">
    This is sample text to fill the space.
  </p>
</div>

3. Theme Extend

This may not be the optimal solution, as selecting the parent of an element is not possible, but in some scenarios, it could be effective) - this approach is not highly recommended

module.exports = {
  theme: {
    extend: {
      screens: {
        'mygroup-hover': { 'raw': '(hover: hover) {.group :hover}' },
      },
    },
  }
}
<div id="card" class="group">
  <p class="text-blue-400 mygroup-hover:text-red-400">
    This is sample text to fill the space.
  </p>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Trouble with Bootstrap modal not popping up following the switch to Bootstrap 5 and jQuery 3 on ASP.NET Core platform

In a recent update, I made changes to jQuery and Bootstrap versions in my ASP.NET Core project. After updating jQuery from v2.2.4 to v3.7.1 and Bootstrap from v2.2.2 to v5.0.2, I encountered an issue where modal pop-ups were not triggering when buttons wer ...

How can I make a fixed background image with NextJS's Next/Image feature?

Lately, I've been exclusively using Next/Image due to Vercel's powerful image optimization service. While I've successfully replaced background-image with DIVs and z-index in most scenarios, I'm facing challenges in achieving two specif ...

Unusual outcome observed when inputting a random number into HTML using JavaScript

In my HTML file, I am trying to input a number within 50% of a target level into the "Attribute" field. Here is the code: <!DOCTYPE html> <html> <body> <input type = "number" name = "playerLevel" onchan ...

Attempting to align the dropdown menu to the left side

This is a challenge I'm facing: https://i.sstatic.net/d3PtN.png I'm attempting to align it in the following way: https://i.sstatic.net/GCwEO.png Below is the HTML code snippet: <li class='list-group-item'> <!-- The dropdow ...

What is the method to identify the specific values causing a div to overflow in every direction?

Is there a method to accurately determine the specific quantities by which a div is overflowing in each direction? The information I found online only helped me calculate total horizontal or vertical overflow values. However, I am interested in knowing t ...

Bootstrap 4 Carousel featuring Shadowed Circles

I am attempting to incorporate two features into a Bootstrap 4 carousel: 1- Add shadow to the text on top of the image in the carousel-caption 2- Display indicators in circular format with numbers inside them I would like the final result to resemble th ...

Ways to reload a webpage from the bottom without any animation

It seems common knowledge that refreshing a webpage on mobile devices can be done by pulling down from the top. However, I am looking to shake things up and refresh the page by pulling up from the bottom instead. And I prefer no animations in the process. ...

"I'm facing an issue with aligning elements in my ReactJS application using CSS Flexbox. Despite setting up a flexbox layout, I am unable to

Despite setting up a flexbox to align my elements, I am struggling with vertical centering on my page. I have made sure to use a container for the page and set brute size with viewport units. Here is my sandbox: https://codesandbox.io/s/rlk3j68pmq. Belo ...

position the next and previous buttons of the bootstrap carousel to be located outside of the images

I am currently using a bootstrap carousel with the following code: <div class="slider-main-container d-block"> <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel"> ...

Issue with CSS wrapper background not displaying

I am currently working with a layout that looks like this: <div class="contentWrapper"> <div class="left_side"></div> <div class="right_side"></div> </div> The contentWrapper class is styled as follows: .contentWrappe ...

Creating smooth curves in SVG path elements using corner rounding techniques

I'm attempting to create a rectangle with rounded corners using the path element, but I've encountered an issue where the stroke width of the round corners is greater than that of the straight lines. Take a look at the code snippet below for the ...

The underline feature may not function correctly when applied to Bootstrap 5 navigation links

I am currently working on a website using Bootstrap 5, and I'm facing an issue with creating underlines for the navigation links in the navbar upon hovering. The problem is that the underline is only appearing for the "services" nav link. Here&apo ...

Assign the chosen option value to a PHP variable for storage

Is there a way to assign the selected value of a select input to a php variable? I'm trying to take the value that is selected in a select box and store it in a php variable, then echo out the selected option value. However, I am having trouble access ...

What is the best way to select a random item from multiple arrays depending on a checkbox selection?

I am looking to display only the text from selected arrays using checkboxes. For example, if I choose only txt and ran, the output should only include elements from those arrays. function myFunc() { let txt = ["txt1", "txt2", "txt3"]; let test = ["t ...

When making jQuery Ajax calls, the $_POST variable may be empty and a warning about headers already being sent may also

I've been working on a PHP project and encountered an issue with sending data from an HTML page using jQuery Ajax to another PHP page. After numerous attempts to debug the problem, I still can't figure out why $_POST is empty when I try to echo. ...

List of C# Request.Browser.Types

I need to detect the browser my users are using because display:none is utilized frequently on a website I am managing. It is crucial that we ensure users are utilizing browsers that support this CSS property. Although Request.Browser.Type provides a stri ...

Bootstrap: An interactive button embedded within a jumbotron featuring a dynamic image size adjustment

My design includes a jumbotron with a responsive image, where the image scales according to the screen size. <div class = 'jumbotron'> <button type= 'button' id="read" class='btn btn-primary'>Button</button& ...

I'm puzzled as to why the color isn't showing up on my navigation bar even though I used "padding: 10px !important;"

I really need help with this, I'm quite new to all of this and it's really confusing me. When I remove this line, the color shows up again, but when I add it back in, it just disappears. I've been following a tutorial on YouTube on how to cr ...

Has jQuery UI Accordion taken over the design of unordered lists?

I'm having trouble with my website's navigation styling getting messed up by the jQuery accordion. The unordered list inside the .accordion div is overflowing and losing its CSS styling. I've tried adding clearStyle true and autoHeight false ...

Using jQuery to position an element above an ID

I'm currently working on a unique portfolio gallery for my website, but I've encountered a problem. What I'm aiming for is to create a gallery that will slide up when a thumbnail is clicked, without loading all images on the page at once. T ...