I'm trying to apply shadow around a box, usually, the shadow applied through tailwind pre-defined classes doesn't show on the top edge, so we need a bit of tweaking for having it shown on all four sides of the element. I tried to add shadow through the tailwind arbitrary class but it's still not showing.
My code looks like:
import React from "react";
export default function HomePage() {
return (
<div className="flex flex-col space-y-24">
<div className="m-12 border border-[#e6e6e6] h-40 w-1/2 px-8 bg-white rounded-3xl drop-shadow-[10px_35px_60px_10px_rgba(60,60,60, 0.5)">
<h1 className="text-3xl">Box</h1>
</div>
<div className="m-12 border border-[#e6e6e6] h-40 w-1/2 px-8 bg-white rounded-3xl shadow-[10px_35px_60px_10px_rgba(60,60,60, 0.5)">
<h1 className="text-3xl">Box</h1>
</div>
</div>
);
}
And here is the complete sandbox example for this.
https://codesandbox.io/s/box-shadow-9zzvnd?file=/src/components/Homepage.js:0-532
The shadow class is not a built-in class in tailwind. Instead, you can define your custom shadow using the box-shadow propertyy. The updated code should work with your HomePage component.
import React from "react";
export default function HomePage() {
return (
<div className="flex flex-col space-y-24">
<div
className="m-12 border border-[#e6e6e6] h-40 w-1/2 px-8 bg-white rounded-3xl"
style={{
boxShadow: "10px 35px 60px 10px rgba(60,60,60, 0.5)"
}}
>
<h1 className="text-3xl">Box</h1>
</div>
<div
className="m-12 border border-[#e6e6e6] h-40 w-1/2 px-8 bg-white rounded-3xl"
style={{
boxShadow: "10px 35px 60px 10px rgba(60,60,60, 0.5)"
}}
>
<h1 className="text-3xl">Box</h1>
</div>
</div>
);
}
Let me know if the code is still not working, I'll be happy to help
Related
import { Inter } from "#next/font/google";
const inter = Inter({ subsets: ["latin"] });
export default function Nav() {
return (
<nav className="bg-gray-800, bg-slate-900">
<div className="container mx-auto px-6 py-4 flex flex-wrap">
<div className="px-4 py-2 rounded-lg text-white hover:bg-gray-700">
{" "}
Home
</div>
<div className="px-4 py-2 rounded-lg text-white hover:bg-gray-700">
Jobs
</div>
</div>
</nav>
);
}
I have this and it is not showing as horizontally but vertically. How can I change this to horizontal?
Something like that could be done using flexbox, or grid; both of which are built into TailwindCSS. In your case it would look something like this:
<nav className=" flex flex-row ...">
<!-- your nav content -->
</nav>
You can read more on flexbox and how to use Tailwind CSS for your layouts here.
I am trying to render a button group with 3 buttons, but I am getting a space in between these. Below is my code
<div className=" mt-2 flex items-center justify-center ">
<div
className="mt-1 inline-flex shadow-lg "
role="group"
>
{products.map((product) => {
return (
<div key={product.id}>
<button
type="button"
onClick={() => {
setPName(product.name);
setPId(product.id)
}}
className="prodButton float-left px-6 md:px-8 py-3 text-black text-xs font-pixeloid leading-tight inline-block focus:text-white transition duration-150 ease-in-out"
>{product.name.toUpperCase()}</button>
</div>
)
})}
</div>
</div>
CSS for the class
.prodButton
{
background-image: url('/assets/images/Buttons/ProdButton.png');
background-size: 100% 100%;
}
Below is how the group is looking
I cant seem to remove the white space in between. Please suggest
Thanks in advance!
So I have created a website(deployed on Vercel) for practice and built it responsive by having breakpoints for different screen sizes. But now, when I see the same website's dashboard page on my mobile, I see some extra unwanted space in its right-top corner and in its index page's desktop view; the footer is, for some reason floating above the bottom of the screen. I have pictures below of desktop view of the footer and dashboard page as shown in Edge and as shown in Chrome Android.
I have built it using React and Tailwind CSS. My website's link is
Dashboard link - https://build2-eight.vercel.app/dashboard
Index Page - https://build2-eight.vercel.app/
And in my development server, neither of the issues were encountered.
The code is:-
/* Index.css custom tailwind classes */
#layer components{
.cardMainPage{
box-shadow:0px 0px 15px rgb(0,0,0,0.32);
#apply flex flex-col items-center justify-start text-2xl gap-5 p-2 py-3 rounded-md bg-white;
}
.Icons{
#apply bg-[#aff0cc] rounded-full h-16 md:h-8 w-16 md:w-8 flex flex-row justify-center items-center cursor-pointer hover:bg-white;
}
.HeaderIcons{
#apply bg-[#aff0cc] p-2 h-8 w-8 rounded-sm hover:bg-white cursor-pointer;
}
}
React Code : -
/* Footer React code */
import React from 'react';
export default function Footer() {
return (
<div className='bg-[#5cdb95] text-[#05386b] w-full text-md flex items-center justify-center'>
<div className='text-center'>
Made with <b className='text-red-600 text-lg'>♥</b> by <a href="/" className=' underline hover:no-underline'>Soumya Deep Sarkar</a>
</div>
</div>
)
}
Dashboard code->
/* Dashboard page code */
import React from "react";
import Header from "../header/index";
import Footer from "../footer/index";
import { GrBitcoin, GrGamepad } from "react-icons/gr";
import { SiCodingninjas } from "react-icons/si";
import { FiSearch } from "react-icons/fi";
import { FcSettings, FcBusinessman } from "react-icons/fc";
import { IoMdNotifications } from "react-icons/io";
import {GrChat} from "react-icons/gr"
export default function Dashboard() {
return (
<div className="flex flex-col h-screen">
<Header />
<div className="flex flex-row h-full">
<div
id="left-side-menu"
className="p-2 px-1 bg-back py-4 flex justify-between h-full flex-col"
>
<div className=" flex flex-col gap-3">
<span className="Icons">
<GrBitcoin />
</span>
<span className="Icons">
<GrGamepad />
</span>
<span className="Icons">
<SiCodingninjas />
</span>
</div>
<div className="flex flex-col gap-3">
<span className="Icons">
<FcSettings />
</span>
<span className="Icons">
<FcBusinessman/>
</span>
</div>
</div>
<div id="center-menu" className="flex flex-col w-full">
<div className="bg-[#20d876] w-full flex flex-row justify-between items-center px-4">
<span className="HeaderIcons my-1"><IoMdNotifications className="text-yellow-500"/></span>
<form className="w-full flex flex-row items-center justify-center p-1">
<span className="relative flex items-center">
<input type="text" className="border-2 px-2 rounded-md border-text "/>
<span className="absolute right-1 cursor-text"><FiSearch/></span>
</span>
</form>
<span className="HeaderIcons"><GrChat className="text-yellow-500"/></span>
<div>
</div>
</div>
</div>
<div id="right-side-menu"></div>
</div>
<Footer />
</div>
);
}
I have figured it out. The textbox(search one) is causing the issue in case of the dashboard header. To fix it I just have to define its width to 100% and it worked out.
Regarding the footer issue. I had to define the minimum height of the window. So I set min height to 100vh.
In tailwind css, for the dashboard header I just put w-full in the className attribute and for the footer I put min-h-screen in the parent div.
I'm trying to create a sticky header with TailwindCSS but can't seem to make it work.
I've read the docs and seems that i only need to add sticky top-0 to my div to make it sticky, but it doesn't work.
I've tried to clean up my code as best as I could for the sake of readability, but if you are intrested in the entire code you can find it here.
import { Logo, ToolbarButton, IconLink, Countdown } from "#lib/atoms";
import { faWhatsapp, faFacebook } from "#fortawesome/free-brands-svg-icons";
import {
faHandHoldingHeart,
faHeadphonesAlt,
} from "#fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "#fortawesome/react-fontawesome";
export const Toolbar = () => {
return (
<div className="flex flex-col drop-shadow-2xl">
<div className="h-16 flex items-center justify-center bg-rs-secondary">
<div className="container flex justify-between">
<div className="flex gap-4 items-center">
<IconLink
icon={faFacebook}
href="https://www.facebook.com/estereo.sulamita"
/>
<IconLink icon={faWhatsapp} href="https://wa.link/logvtp" />
</div>
<Countdown />
</div>
</div>
{/* I want this div to be sticky */}
<div className="sticky top-0 h-20 flex justify-center bg-white">
<div className="container flex items-center h-full justify-between">
<Logo />
<div className="flex">
<ToolbarButton>Inicio</ToolbarButton>
<ToolbarButton>Videos</ToolbarButton>
<ToolbarButton>Colaboradores</ToolbarButton>
<ToolbarButton
className="group"
hoverBackgroundColor="hover:bg-black"
primary={true}
>
<FontAwesomeIcon
icon={faHandHoldingHeart}
className="group-hover:text-white w-4"
/>
</ToolbarButton>
<ToolbarButton
backgroundColor="bg-rs-primary"
hoverBackgroundColor="hover:bg-black"
textColor="text-white"
primary={true}
>
Reproducir
<FontAwesomeIcon icon={faHeadphonesAlt} className="w-4 ml-3" />
</ToolbarButton>
</div>
</div>
</div>
</div>
);
};
The above code renders the following component:
Also, you can find a deployed version of my app here.
I'd like to achieve something like this with my header component.
Any help is much appreciated.
sticky element should be direct child of the scrollable element.
In your case scrollable element is the root __next container. Basically it means that you need to remove this div <div className="flex flex-col drop-shadow-2xl"> and replace it with React.Fragment so both of your headers, Countdown and second Header, would be direct children of this scrollable div.
I have this react component:
const Status = () => {
return (
<div className='h-screen bg-gray-800 flex justify-center items-center p-16'>
<div className='bg-gray-700 px-8 py-4 rounded w-full'>
<h2 className='text-2xl text-gray-100 font-medium'>Plex Server</h2>
<h3 className='text-base text-gray-400'>Added 22/10/2021</h3>
<div className='flex flex-row w-full space-x-1 my-4'>
{[...Array(30)].map((i, idx) => (
<div key={idx} className='h-8 w-1 bg-green-400 rounded'></div>
))}
</div>
</div>
</div>
);
};
export default Status;
I'm using it to render 30 flex children with hard-coded width of 4px (w-1 class). Here is the result:
Is there a way to set children width automatically so it would fill up parent space equaly?
For example: parent width is 100px and this time I want to render only 10 elements. With current code it will take only 76px (40px from child width + 36px from 4px space between them). Is there a way to set children width automatically to ~6px?
You can do it by using flex-1 instead of w-1 and it will take width automatically such as:
const Status = () => {
return (
<div className='h-screen bg-gray-800 flex justify-center items-center p-16'>
<div className='bg-gray-700 px-8 py-4 rounded w-full'>
<h2 className='text-2xl text-gray-100 font-medium'>Plex Server</h2>
<h3 className='text-base text-gray-400'>Added 22/10/2021</h3>
<div className='flex flex-row w-full space-x-1 my-4'>
{[...Array(30)].map((i, idx) => (
<div key={idx} className='h-8 flex-1 bg-green-400 rounded'></div>
))}
</div>
</div>
</div>
);
};
export default Status;
Here is a working example of it: https://play.tailwindcss.com/rYFniYTQe6
Here is how it will look: