Having trouble getting the Image
component to behave like the img
element? Can anyone provide a solution for making Image
achieve the same result as shown in the example below?
<div style={{ width: "100vw", height: "100vh", display: "flex" }}>
{/* img */}
<div style={{ width: "50%", height: "100%", background: "red" }}>
<img
src="https://t4.ftcdn.net/jpg/03/00/94/69/360_F_300946931_kSR84OqudEhsmBZH47HU6ud7aZIDMjEx.jpg"
alt=""
style={{ width: "100%", height: "100%", objectFit: "cover" }}
/>
</div>
{/* Image */}
<div style={{ width: "50%", height: "100%", background: "blue" }}>
<Image
src="https://t4.ftcdn.net/jpg/03/00/94/69/360_F_300946931_kSR84OqudEhsmBZH47HU6ud7aZIDMjEx.jpg"
alt=""
width="1"
height="1"
layout="responsive"
objectFit="cover"
/>
</div>
</div>
Output: https://i.sstatic.net/q5qj7.jpg
#UPDATE This is the answer.
{/* Image */}
<div
style={{
width: "50%",
height: "100%",
background: "blue",
position: "relative",
}}
>
<Image
src="https://t4.ftcdn.net/jpg/03/00/94/69/360_F_300946931_kSR84OqudEhsmBZH47HU6ud7aZIDMjEx.jpg"
alt=""
layout="fill"
objectFit="cover"
/>
</div>
Output: https://i.sstatic.net/Oav80.jpg