#image stuff D
1 messages · Page 1 of 1 (latest)
Btw I have tested the solution that I have proposed and it works for me
using next Image
using standard <img
The current code:
import { Box } from "@chakra-ui/react";
import * as React from "react";
import Image from "next/image";
const ChakraNextImage = (props: {
[x: string]: any;
src: string;
alt: string;
}) => {
const { src, alt, ...rest } = props;
return (
<Box position="relative" height="300px" {...rest}>
<Image
objectFit="contain"
layout="fill"
width="100%"
src={src}
alt={alt}
/>
</Box>
);
};
export default ChakraNextImage;
My Layout
<Box
marginTop={{ base: "1", sm: "5" }}
display="flex"
flexDirection={{ base: "column", sm: "row" }}
justifyContent="space-between"
>
<Box display="flex" flex="1" position="relative" alignItems="center">
<Box
width={{ base: "100%", sm: "85%" }}
zIndex="2"
marginLeft={{ base: "0", sm: "0%" }}
marginTop="5%"
>
<Link textDecoration="none" _hover={{ textDecoration: "none" }}>
<ChakraNextImage
borderRadius="lg"
src={image}
alt={title}
layout="fill"
objectFit="contain"
/>
</Link>
</Box>
...
You don't have classname on NextImage
you have added width="100%". this won't work
No on <Image className="image-styles"/> in your css: .image-styles { width: 100%}
I would also suspect the flex at fault, but let's start with that.
hmm but it already contains the width: 100% inline here
<Image
objectFit="contain"
layout="fill"
-> width="100%"
src={src}
alt={alt}
/>
am I blind? 🐒
which accepts only numbers, not strings.
width={100}
but this is in pixels
If you use layout full, the widht and height prop are ignored on IMage
I should be able to do something like this in Chakra
<Image
width={"100%"}
objectFit="contain"
layout="fill"
src={src}
alt={alt}
/>
but same issue
No, like I said. This is a prop which only accepts a number width={100}, but you're still passing string width={"100"} .But still that number is recongized as pixels, not % and is also ignored with layout="fill"
THis need to be a className
ok I got it now
<Box boxSize="sm" position="relative" {...rest}>
<Image layout="fill" objectFit="contain" src={src} alt={alt} />
</Box>
boxSize makes a difference
thanks
could be, I don't know Chakra that well.