This is the second part of my videos on integrating the Shadcn/ui library with laravel. In this video I go into how you can pass validation errors from the server into your Shadcn form component.
Its pretty common to see a hero section on a landing page. These usually have an image in the background, some kind of overlay and then some title text and a button of some kind.
For some reason, I feel like I always have to rediscover the best way to place that background image and overlay so I decided I’m just going to write it down.
Nextjs has an Image component that allows you to take images and basically convert them on the fly. Its really handy but mostly only works for standard images and not background images.
You can use the Image component as a background image though if you do something like this-
<divclassName="relative w-full overflow-hidden h-[100svh] md:h-[70svh]"><Imagesrc='https://example.com/images/myimage.webp'alt="Amazing Image"layout="fill"objectFit="cover"className="w-full h-full object-top"/><divclassName="absolute inset-0 bg-gray-800 opacity-60"></div><divclassName="absolute inset-0 flex flex-col w-4/5 sm:w-3/5 justify-center mx-auto text-white space-y-8"><h1className="text-5xl lg:text-7xl font-bold uppercase">
Join my amazing ball point pen club
</h1><h3className="text-2xl uppercase font-roboto font-thin">
Never commit another sub optimal pen stroke
</h3><divclassName="flex items-center justify-center"><buttonclassName="bg-black rounded-full px-8 py-4 text-xl uppercase font-roboto">Join Now
</button></div></div></div>
So the image tag there will create the background image. The absolutely positioned div below it will provide the overlay and last div has the content. Why not just use a background image?
Background images can’t take advantage of the next/image component and so won’t be automatically optimized for you.
What if I’m not using nextjs? You can still use this technique although a background image might work just as well. Here is the html that component generates for you. You could apply this same technique to any image tag
Here is another video I made where I talk about the shadcn/ui library, how you can use it with laravel and I go into more details about setting up form validation on the client.