[英]I am using Swiper Library to create carousel. i want to center my card element in center but i am not able to do
I am using Swiper Library to create carousel.我正在使用 Swiper 库创建轮播。 i want to center my card element in center but i am not able to do.我想将我的卡片元素居中,但我做不到。 here is important component code please help me.这是重要的组件代码,请帮助我。 i am using styled component with swiper library.我正在使用带有 swiper 库的样式化组件。
const Wrapper = styled(motion.div)`
height: 200px;
min-width: 300px;
width: 300px;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
position: relative;
&:hover ${Desc} {
transform: translateY(0%);
}
`;
const Card = () => {
return (
<Swiper pagination={true} modules={[Pagination]}>
{sliderItems.map((item) => {
return (
<SwiperSlide key={item.id}>
<Wrapper>
<Title>{item.title}</Title>
<Desc>{item.desc}</Desc>
<Img src={item.img} />
</Wrapper>
</SwiperSlide>
);
})}
</Swiper>
);
};
why my Wrapper div take this extra space.为什么我的 Wrapper div 占用了这个额外的空间。 because of that next element is not visible on screen.因为下一个元素在屏幕上不可见。
You have to center card element in your parent element, or if your parent element is grid you can use justify-self: center;
你必须在你的父元素中居中卡片元素,或者如果你的父元素是网格,你可以使用justify-self: center;
you can also try:你也可以试试:
margin: 0 auto;
or center absolute with:或中心绝对值:
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.