Reputation: 803
I make a container and I want to change its background color after the user clicks that container but the problem is, it is a div, and the focus state is not working on the div but the active state is working,
<div className="flex space-x-3 items-center hover:bg-messenger-gray-100 focus:bg blue-50 relative p-2 rounded-lg group cursor-pointer border active:bg-blue-50">
{/* the code above on the top level div is not working*/}
{/* Focus is not working on this div */}
{/* active state works */}
<span className=" font-normal whitespace-nowrap ">Muhammad Hamza</span>
</div>
<span></span>
?Upvotes: 0
Views: 1093
Reputation: 3905
You can not apply focus
for div or span. However to achieve you can try one of the hack I use. You can define the thing in button.
Below is the code:
<script src="https://cdn.tailwindcss.com"></script>
<div class="p-10">
<div class="flex space-x-3 items-center hover:bg-messenger-gray-100 relative p-2 rounded-lg group cursor-pointer border active:bg-blue-50">
<span class=" font-normal whitespace-nowrap">Muhammad Hamza</span>
</div>
<button class=" w-full flex my-4 items-start hover:bg-gray-100 p-2 rounded-lg group cursor-pointer border active:bg-blue-50 focus:bg-pink-300 focus:border-pink-500"> Muhammad Hamza with focus </button>
</div>
Upvotes: 1