I'm in the process of creating a website using Nextjs, React, and TailwindCSS, and I aim to design a Hero section that resembles the one on the following website.
https://i.sstatic.net/tq3zW.png
My goal is to:
- Have a text title and buttons on the left side
- Display a PNG image on the right side with
right-0
positioning - Ensure the image size changes dynamically while maintaining a responsive aspect ratio
Currently, my image widens as the screen size increases and I struggle to control its size effectively. Setting max-w-4xl
helps but doesn't keep it aligned to the right-0
.
<div tw="inset-y-0 right-0 pl-4 -mr-40 h-full pl-12 max-w-4xl"> <- specified max width here
<Image src={PNGImage} tw="h-full w-auto" alt="Image" />
</div>
This is how I currently have it structured.
<div tw="flex flex-row ml-16 relative overflow-hidden">
<div tw="flex flex-col">
<h1
tw="text-white-default font-bold text-2xl text-center"
className="whitespace-pre-wrap laptop:text-[48px]"
>
Some title text...
</h1>
</div>
<div tw="inset-y-0 right-0 pl-4 -mr-40 h-full pl-12">
<Image src={PNGImage} tw="h-full w-auto" alt="Image" />
</div>
</div>
I believe I need to introduce an absolute
value to achieve correct responsiveness, although I am unsure about the best approach for this.
Here are some example websites I found with a similar structure.