Bru*_*que 4 typescript reactjs styled-components next.js nextjs-image
我可以将“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)
小智 5
将您的图像放在您喜欢的位置的另一个父 div 中。在你的情况下:
import React from 'react'
import Image from 'next/image'
import styled from 'styled-components'
const Container = styled.div`
position: relative;
`
const ImageContainer = styled.div`
position: absolute;
left: 50%;
`
const Page: React.FC = () => {
return (
<Container>
<ImageContainer>
<Image src{someImg.webp} width={500} height={500} objectFit="none"/>
</ImageContainer>
</Container>
)
}
export default Page;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12439 次 |
| 最近记录: |