how to center <div> (jk)
Answered
Laysan Albatross posted this in #help-forum
Laysan AlbatrossOP
export default function LandingPage() {
return (
<div className="flex items-center justify-center">
<div className="grid grid-cols-2 space-x-2 space-y-4">
<div className="col-span-2 w-64">
<IamAnimated />
</div>
<div className="col-span-1">
<DrawerDownloadFiles />
</div>
<div className="col-span-1">
<ButtonGetStarted />
</div>
<SvgSatellite className="w-32" />
</div>
</div>
)
}
I have this grid and want to center <IamAnimated>. How? 😄
Answered by SharpieMaster
export default function LandingPage() {
return (
<div className="flex items-center justify-center">
<div className="grid grid-cols-2 space-x-2 space-y-4">
<div className="col-span-2 flex items-center justify-center text-center">
<button>Thing</button>
</div>
<div className="col-span-1 text-center">
<button>Download</button>
</div>
<div className="col-span-1 text-center">
<button>Contact Me</button>
</div>
<div className="col-span-2 flex items-center justify-center">
<button>Login With Email</button>
</div>
<button>Idk what this one is</button>
</div>
</div>
);
}
20 Replies
export default function LandingPage() {
return (
<div className="flex items-center justify-center">
<div className="grid grid-cols-2 space-x-2 space-y-4">
<div className="col-span-2 w-64 flex items-center justify-center">
<IamAnimated />
</div>
<div className="col-span-1">
<DrawerDownloadFiles />
</div>
<div className="col-span-1">
<ButtonGetStarted />
</div>
<SvgSatellite className="w-32" />
</div>
</div>
)
}
Laysan AlbatrossOP
tried that before, doesnt work 😦
try inspect element and see what is going wrong
Laysan AlbatrossOP
I wanna center the first Svg and the Login with Email button
So the struggle is not to center the whole grid in the middle of the page - that already works fine.
So the struggle is not to center the whole grid in the middle of the page - that already works fine.
export default function LandingPage() {
return (
<div className="flex items-center justify-center">
<div className="grid grid-cols-3 space-x-2 space-y-4">
<div className="col-span-3 w-64">
<IamAnimated />
</div>
<div className="col-span-1">
<DrawerDownloadFiles />
</div>
<div>
<DrawerContact />
</div>
<div className="col-span-3 w-full">
<ButtonGetStarted />
</div>
<SvgSatellite className="w-32" />
</div>
</div>
)
}
sorry, I cant really help you without the specific components you are using
Laysan AlbatrossOP
DrawerDownloadFiles.tsx
DrawerContact.tsx
ButtonGetStarted.tsx
import { EnvelopeOpenIcon } from '@radix-ui/react-icons'
import { Button } from '@/components/ui/button'
export function ButtonGetStarted() {
return (
<Button>
<EnvelopeOpenIcon className="mr-2 h-4 w-4" /> Login with Email
</Button>
)
}
IamAnimated.tsx
but I'm pretty sure the components have nothing to do with my issue
export default function LandingPage() {
return (
<div className="flex items-center justify-center">
<div className="grid grid-cols-3 space-x-2 space-y-4">
<div className="col-span-3 w-64">
<button>Thing</button>
</div>
<div className="col-span-1">
<button>Download</button>
</div>
<div>
<button>Contact Me</button>
</div>
<div className="col-span-3 w-full">
<button>Login With Email</button>
</div>
<button>Idk what this one is</button>
</div>
</div>
);
}
Something like this?
Laysan AlbatrossOP
wanna center it like this
export default function LandingPage() {
return (
<div className="flex items-center justify-center">
<div className="grid grid-cols-2 space-x-2 space-y-4">
<div className="col-span-2 flex items-center justify-center text-center">
<button>Thing</button>
</div>
<div className="col-span-1 text-center">
<button>Download</button>
</div>
<div className="col-span-1 text-center">
<button>Contact Me</button>
</div>
<div className="col-span-2 flex items-center justify-center">
<button>Login With Email</button>
</div>
<button>Idk what this one is</button>
</div>
</div>
);
}
Answer
you cant set a width and a col-span at the same time, if you want to adjust the width you can change the whole grid width
idk why you were using 3 columns on the grid
I just added text center because I was using buttons for the example
Laysan AlbatrossOP
Thank you so much!