【发布时间】:2021-04-21 03:05:49
【问题描述】:
我正在尝试在 react 中做 Instagram 用户的照片布局,实际上我之前在 css 网格课程中做过
问题是,这次不行,我不知道怎么做,我尝试了很多东西,我不知道为什么我的 img 没有调整到我想要的尺寸
让我给你看代码
所以,我就是这样做的
return (
<UserPhotosHero>
<ContainUserPhotos>
{specificPhotos &&
specificPhotos.map(photo => {
return (
<AnimatePresence>
<UserPersonalPhotos
key={photo.id}
variants={PopUp}
initial="hidden"
animate="visible"
>
<img src={photo.photo} />
</UserPersonalPhotos>
</AnimatePresence>
);
})}
</ContainUserPhotos>
</UserPhotosHero>
);
};
这些是样式
// User Photos
export const UserPhotosHero = styles.section`
width: 75%;
min-height: 40vh;
margin: auto;
margin-bottom: 6rem;
margin-top: 4.5rem;
`;
export const ContainUserPhotos = styles.div`
display: grid;
grid-template-columns: repeat(3, minmax(100px, 293px));
justify-content: center;
grid-gap: 2.8rem;
`;
export const UserPersonalPhotos = styles(motion.div)`
position: relative;
cursor: pointer;
z-index: 2;
img{
width: 100%;
height: 100%;
object-fit: contain;
}
`;
预期输出:正如我之前提到的,我在另一门课程中做到了,我必须查看代码,以便我可以引导自己,并且,我期望发生什么是,3列,每列是一个div,每个div的大小将是宽度293px,高度293px,如果我关闭窗口,它会调整宽度和高度,但是,这就是我得到的
我期望的宽度的图像,但高度不接近 293 像素
Instagram's (ugly) layout photo
为什么 img 的大小没有接近 293px ?我做错了什么?
【问题讨论】:
标签: css styled-components