Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying button when hovering over div in TailwindCSS

At the moment I am having a bit of trouble using TailwindCSS to display a button when hovering over a div in Vue. Normally, I'd use CSS to do it but I want to do it using tailwind.

I referred to the documentation using visibility but it didn't work as expected. Is visibility normally for screen related elements? or it can be used for buttons and other content as well?

Code

<div>
  <button class="text-white invisible hover:visible">Hello</button>
</div>
like image 857
penguin Avatar asked Mar 29 '20 16:03

penguin


People also ask

How do you add multiple hover effects in tailwind?

We can use Tailwind's hover modifier to create hover effects for elements. While we can target and style different properties of an element on hover, Tailwind does not allow us to chain multiple classes to a single hover instance. Even though we use multiple hover modifiers, they will all fire simultaneously.

How do you hide an element in tailwind?

Use invisible to hide an element, but still maintain its place in the DOM, affecting the layout of other elements (compare with .hidden from the display documentation).

How do I stop the scroll in tailwind?

Use overscroll-none to prevent scrolling in the target area from triggering scrolling in the parent element, and also prevent “bounce” effects when scrolling past the end of the container.

Can you use tailwind with flutter?

Tailwind CLIA simple yet awesome flutter package to generate and use TailwindCSS like styling in your flutter projects.


1 Answers

Add this to your tailwind.config.js file

variants: {
    extend: {
        display: ["group-hover"],
    },
},

And then add group to your parent div and hidden and group-hover:block to your child element that you want to appear on hover of the parent.

<div class="group">
  <button class="hidden group-hover:block">Child</button>
</div>
like image 61
Julian Avatar answered Oct 09 '22 21:10

Julian