I’m attempting to create a layout where I have an image that sticks to the left side of the viewport while scrolling until the content ends, at which point it should scroll to the next section.
However, despite trying various approaches, I can’t seem to get the image to stick properly.
<div className="relative py-24 overflow-hidden bg-gray-900 sm:py-32">
<div className="px-6 mx-auto max-w-7xl lg:px-8">
<div className="grid max-w-2xl grid-cols-1 mx-auto gap-x-8 gap-y-16 sm:gap-y-20 lg:mx-0 lg:max-w-none lg:grid-cols-2">
<div className="lg:ml-auto lg:pl-4 lg:pt-4">
<div className="lg:max-w-lg">
<h2 className="text-base font-semibold leading-7 text-indigo-600">Deploy faster</h2>
<p className="mt-2 text-3xl font-bold tracking-tight text-gray-100 sm:text-4xl">A better workflow</p>
<p className="mt-6 text-lg leading-8 text-gray-400">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Maiores impedit perferendis suscipit eaque,
iste dolor cupiditate blanditiis ratione.
</p>
<dl className="max-w-xl mt-10 space-y-8 text-base leading-7 text-gray-400 lg:max-w-none">
{features.map((feature) => (
<div key={feature.name} className="relative pl-9">
<dt className="inline font-semibold text-gray-100">
<feature.icon className="absolute w-5 h-5 text-indigo-600 left-1 top-1" aria-hidden="true" />
{feature.name}
</dt>{' '}
<dd className="inline">{feature.description}</dd>
</div>
))}
</dl>
<dl className="max-w-xl mt-10 space-y-8 text-base leading-7 text-gray-400 lg:max-w-none">
{features.map((feature) => (
<div key={feature.name} className="relative pl-9">
<dt className="inline font-semibold text-gray-100">
<feature.icon className="absolute w-5 h-5 text-indigo-600 left-1 top-1" aria-hidden="true" />
{feature.name}
</dt>{' '}
<dd className="inline">{feature.description}</dd>
</div>
))}
</dl>
</div>
</div>
<div className="flex items-start justify-end lg:order-first lg:sticky lg:top-4">
<img
src="https://tailwindui.com/img/component-images/dark-project-app-screenshot.png"
alt="Product screenshot"
className="w-[48rem] max-w-none rounded-xl shadow-xl ring-1 ring-gray-400/10 sm:w-[57rem]"
width={2432}
height={1442}
/>
</div>
</div>
</div>
</div>
I tried adding stick top-4
to the div enclosing the image but still it doesnt seem to be sticky when scroll.
Link: https://play.tailwindcss.com/Ur3gB0pIcj