小编Bru*_*que的帖子

如何将 next/image 中的 Image 组件放在位置:absolue

我可以将“next/image”中的元素图像放入其中吗{ position: absolute; left: 50% }?看来并没有受到影响。

例子:

import React from 'react'
import Image from 'next/image'
import styled from 'styled-components'

const Container = styled.div`
  position: relative;
`

const Test = styled(Image)`
 position: absolute;
 left: 50%;
`

const Page: React.FC = () => {
  return (
    <Container>
      <Test src{someImg.webp} width={500} height={500} objectFit="none" />
    </Container>
  )
}

export default Page;
Run Code Online (Sandbox Code Playgroud)

typescript reactjs styled-components next.js nextjs-image

4
推荐指数
1
解决办法
1万
查看次数