网格中的图片有问题。网格中有四张图片,使用sm:grid-cols-2
时每行显示2张,但图片上的覆盖图大小正确。
当我把光标放在第一张和最后一张图片(1和4)上时,它正确地显示了叠加,但图片本身太小了。第2张和第3张图片的大小正确,叠加非常合适。
我不知道代码哪里出错了,为什么图片大小不一样。如有任何帮助,将不胜感激。
const container = {
hidden: {},
visible: {
transition: {
staggerChildren: 0.2
}
}
};
const projectVariant = {
hidden: { opacity: 0, scale: 0.8 },
visible: { opacity: 1, scale: 1 }
};
const Project = ({ title }) => {
const overlayStyles = `absolute h-full w-full opacity-0 hover:opacity-90 transition duration-500 bg-grey z-30 flex-col flex justify-center items-center text-center p-16 text-deep-blue`;
const projectTitle = title.split(' ').join('-').toLowerCase();
return (
<motion.div variants={projectVariant} className="relative">
<div className={overlayStyles}>
<p className="text-2xl font-playfair">{title}</p>
<p className="mt-7">Description of the project shown</p>
</div>
<img src={`../assets/${projectTitle}.png`} alt={projectTitle} />
</motion.div>
);
};
const Projects = () => {
return (
<section id="projects" className="pt-48 pb-48">
{/* HEADINGS */}
<motion.div
className="md:w-2/5 mx-auto text-center"
initial="hidden"
whileInView="visible"
viewport={{ once: true, amount: 0.5 }}
transition={{ duration: 0.5 }}
variants={{
hidden: { opacity: 0, y: -50 },
visible: { opacity: 1, y: 0 }
}}
>
{/* PROJECTS */}
<div className="flex justify-center">
<motion.div
className="sm:grid sm:grid-cols-2"
variants={container}
initial="hidden"
whileInView="visible"
viewport={{ once: true, amount: 0.2 }}
>
{/* ROW 1 */}
<Project title="Project 1" />
<Project title="Project 2" />
{/* ROW 2 */}
<Project title="Project 3" />
<Project title="Project 4" />
</motion.div>
</div>
</section>
);
};
1条答案
按热度按时间xxb16uws1#
请在www.example.com或类似网站上提供工作示例play.tailwindcss.com