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,
this is the code link
<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>
how can I make the div focusable?
Is this focus property also don't work on <span></span>?
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>
Related
I'm making a blog using NextJS and TailwindCSS. I've made a card, that the button overlays the card image right in the middle. But the button stays a little higher. Image:
And here is the code:
<div className="relative max-w-5xl mx-auto px-2 grid grid-cols-3">
<div className="relative overflow-hidden flex items-center justify-center flex-col">
<Image
src={
"https://static.wixstatic.com/media/5bfb6f_9f2519d5fc2d41f990a10dd92eb8658d.jpg/v1/fill/w_393,h_325,al_c,q_80,usm_0.66_1.00_0.01,enc_auto/5bfb6f_9f2519d5fc2d41f990a10dd92eb8658d.jpg"
}
width={314}
height={314}
alt="Image"
className="object-cover"
/>
<div className="absolute w-full h-full top-0 bottom-0 left-0 right-0">
<button className="text-xl px-4 py-2 rounded text-blue-600 bg-white absolute bottom-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2">Travel</button>
</div>
</div>
</div>
I've tried using absolute and relative positions. I've also tried using flexbox. But nothing worked. I'm expecting that the button will overlay on the image right on the center.
There are many ways to do this, but I think the easiest fix here is, instead of using absolute for the button, just add flex items-center justify-center to the parent class of button like this:
<div class="relative max-w-5xl mx-auto px-2 grid grid-cols-3">
<div class="relative overflow-hidden flex items-center justify-center flex-col">
<img
src="https://via.placeholder.com/314x314"
width="314"
height="314"
alt="Image"
class="object-cover"
/>
<div class="absolute w-full h-full top-0 bottom-0 left-0 right-0 flex items-center justify-center">
<button class="text-xl px-4 py-2 rounded text-blue-600 bg-white">Travel</button>
</div>
</div>
</div>
<script src="https://cdn.tailwindcss.com"></script>
I have a problem. I use react and tailwind css. Th modal is relative and the overlay is flex positioned, because I want the main modal to be positioned in the middle of the screen on X axis. Here it comes the problem. The wrapper that contains the options tag renders in a different place than the parent select. I tried fixing it with absolute position and also with relative one. But nothing works...
Because there is not programming logic, I will paste the code.
<div className="modal flex fade fixed top-0 left-0 w-full h-full outline-none overflow-x-hidden overflow-y-auto" id="exampleModalCenteredScrollable" tabIndex="-1" aria-labelledby="exampleModalCenteredScrollable" aria-modal="true" role="dialog">
<div className=" modal-dialog modal-dialog-centered modal-dialog-scrollable relative w-auto pointer-events-none flex-1 p-2 bg-slate-200">
<div className="modal-content border-none shadow-lg relative flex flex-col w-full pointer-events-auto bg-white bg-clip-padding max-w-2xl mx-auto mt-5 rounded-md outline-none text-current">
<div className="modal-header flex flex-shrink-0 items-center justify-between p-4 border-b border-gray-200 rounded-t-md ">
<h5 className="text-2xl font-bold leading-normal text-gray-700 underline " id="exampleModalCenteredScrollableLabel">
Add new exercice
</h5>
<button type="button" onClick={() => setOpen(!open)}
className="btn-close box-content p-1 text-black border-none rounded-none opacity-50 focus:shadow-none focus:outline-none focus:opacity-100 hover:text-black hover:opacity-75 hover:no-underline"
data-bs-dismiss="modal" aria-label="Close"><AiOutlineCloseCircle color='black' size={30}/></button>
</div>
<div className="modal-body relative p-4">
<p>Look for the exercice you wish to add, and click import. You may add as many exercices you want, however please make sure you will complete them by the end of the day.</p>
<form >
<div className='flex mt-3 flex-col'>
<input required placeholder='Search by word...' className='border border-slate-400 p-1 rounded-md flex-1 max-w-sm my-2'/>
{/* Problem is here!!!! */}
<select className='border border-slate-400 p-1 rounded-md max-w-sm my-2 [&>option]:bg-black'>
<option defaultValue>Slobozel</option>
<option>Slobozel</option>
<option>Slobozel</option>
<option>Slobozel</option>
</select>
</div>
I'm trying to create a hover message within a span. For example, when we hover over the first span (parent span) its child span is shown. That's working fine but the child span is not taking auto width. Here is the code I have tried
<span class="group/item relative ml-2 h-6 w-6 bg-yellow-300">
Hover me
<span class="absolute top-7 right-auto z-10 hidden w-auto rounded-md bg-gray-900 px-3 py-1 text-[10px] text-white group-hover/item:block"> Create payment </span>
</span>
This code gives this result
I want this result
Please note that I want to get this result with w-auto
Add whitespace-nowrap class on you children span which will prevent text from breaking after white spaces. Your span is taking width auto as expected it's just that default behavior of text is to break itself after a white space if there is no width left
<script src="https://cdn.tailwindcss.com"></script>
<span class="group/item relative ml-2 h-6 w-6 bg-yellow-300">
Hover me
<span class="absolute top-7 right-auto z-10 hidden w-auto rounded-md bg-gray-900 px-3 py-1 text-[10px] text-white group-hover/item:block whitespace-nowrap"> Create payment </span>
</span>
I have this div that's supposed to represent a button next to an input. Ideally on resolution change, the input element's width shrinks but the button stays the same height and width.
<div className="flex flex-row rounded-lg border border-white border-solid hover:cursor-pointer py-2 px-2 w-28">
<AddIcon></AddIcon>
<div className="flex font-sans text-base font-medium">Add site</div>
</div>
I set the w-28 property thinking it could achieve this. However, the button changes width if I shrink the window or screen it appears on, and I'm not sure why.
This is the full component:
<div id="settings" className="w-3/4 h-5/6 bg-blue-300 self-center">
<div id="settings-content" className="flex flex-col self-center mx-5">
<div id="header" className="flex flex-col mt-5">
<div id="title" className="font-sans font-bold text-3xl">Block Sites</div>
</div>
<div id="subtitle" className="font-sans text-base font-medium text-neutral-600">Visiting these sites will stop point acquisition until you reset the timer</div>
<div id="block-site-add-list" className="flex flex-row mt-16 justify-between bg-amber-400 shrink-0">
<div className="flex flex-row rounded-lg border border-white border-solid hover:cursor-pointer py-2 px-2 w-28">
<AddIcon></AddIcon>
<div className="flex font-sans text-base font-medium">Add site</div>
</div>
<input className="ml-5 flex-grow bg-red-500"></input>
</div>
</div>
</div>
This is what the button looks like with a smaller screen, when both words should be on the same line:
You could try adding whitespace-nowrap to your label div to ensure that the text doesn't wrap to two lines. Since you have your elements (button and input) wrapped in another flex, you can add shrink-0 to your wrapper div to keep its size.
For example:
<div id="block-site-add-list" className="flex flex-row ...">
<div className="shrink-0 flex flex-row ...">
<AddIcon></AddIcon>
<div className="whitespace-nowrap font-sans text-base font-medium">Add site</div>
</div>
<input className="ml-5 grow bg-red-500"></input>
</div>
I have been trying to make a twitter clone, while making the sidebar I am not able to align the text of "Home" and "Explore". in img you can see "Home" is little bit towards the right. while inspecting I found that faHome icon is of 18x14 size, while faHashtag is of 14x14.
I need to know how I can I keep all button's text and Icon in same alignment.
Following the code for complete screen as shown in image. I am using Tailwind CSS
<div className="flex flex-row">
{--------- Div for Nav Bar ---------}
<div class="px-4 w-80 bg-white flex flex-col justify-start align-center top-0 bottom-0 left-0 fixed">
<div>
<button className="flex p-4 bg-red-500 mb-2 rounded-full mx-auto 2xl:mx-0 2xl:space-x-4 focus:outline-none hover:text-blue hover:bg-blue hover:bg-opacity-20">
<FontAwesomeIcon icon={faHome} className="mr-4 text-xl" />
<span>Home</span>
</button>
<button className="flex p-4 bg-red-500 rounded-full mx-auto 2xl:mx-0 2xl:space-x-4 focus:outline-none hover:text-blue hover:bg-blue hover:bg-opacity-20">
<FontAwesomeIcon icon={faHashtag} className="mr-4 text-xl" />
<span>Explore</span>
</button>
<button className="flex p-4 rounded-full mx-auto 2xl:mx-0 2xl:space-x-4 focus:outline-none hover:text-blue hover:bg-blue hover:bg-opacity-20">
<FontAwesomeIcon icon={faHashtag} size="lg" className="mr-4" />
<span>Explore</span>
</button>
</div>
</div>
{---------------------}
<div className="flex-auto h-screen bg-blue-400">Hello World</div>
<div className="w-96 h-screen bg-gray-400">Hello World</div>
</div>
I want Home and explore to look something like this.
The issue was there because of icons size coming from FontAwesome Icons. though I tried to wrap the size into a div, but that didn't work.
I found out that we can use following to get the desired size of icon.
<FontAwesomeIcon icon={faHome} style={{ width: "20px", height: "230px" }} />