1

I simply want to make sticky card but it does not stick when i scroll

enter image description here

<Box display={'flex'} width={'100%'} height={'150rem'}  >
  <Box width={'100%'}>
    {features.map((feature) => (
      <div key={feature.id}>
        <Typography variant='h2' py={10} color={'grey'}>
          {feature.title}
        </Typography>
      </div>
    ))}
  </Box>
  <Box position={'sticky'} width={'100%'} sx={{ backgroundColor: 'grey' }} top={0} height={'50rem'} alignSelf={'flex-start'} >
    sticky card placeholder
  </Box>
</Box>
Fatih Can
  • 321
  • 4
  • 12

1 Answers1

1

You need to get the sticky element out of the parent <box> since sticky elements only stick to it's parent, if you get that sticky element directtly into the <body> it will stick to the top of the page as you scroll.

 <Box display={'flex'} width={'100%'} position={'relative'} alignItems={'start'}>
  <Box width={'100%'}>
    {features.map((feature) => (
      <div key={feature.id}>
        <Typography variant='h2' py={10} color={'grey'}>
          {feature.title}
        </Typography>
      </div>
    ))}
  </Box>
</Box>
<Box display={'flex'} position={'sticky'} width={'100%'} top={0} height={'100vh'} alignItems={'center'}>
  <Box width={'100%'} height={'50%'} sx={{ backgroundColor: 'grey' }}>
    sticky card placeholder
  </Box>
</Box>
ErnuB
  • 46
  • 7