简体   繁体   English

我正在使用 Swiper 库创建轮播。 我想将我的卡片元素居中,但我做不到

[英]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.因为下一个元素在屏幕上不可见。

在此处输入图像描述

在此处输入图像描述

  • Need output like this需要这样的output 在此处输入图像描述

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.

相关问题 我如何使旋转木马居中? - How do I center my carousel? 我正在使用 Bootstrap 4 轮播。 它适用于所有 Windows 和 android 操作系统,但不适用于 Mac 和 Iphone 操作系统。 有什么解决办法吗? - I am using Bootstrap 4 carousel. Its working on all windows and android OS, but its not working on Mac and Iphone OS. any solution for this? 我正在使用的轮播中的图片不适合整个屏幕 - The pictures in my carousel that I am using do not fit the entire screen 我无法使用 js 创建动态元素计数器 - I am not able to create dynamic element counter using js 我无法居中<script> in my html - I am unable to center my <script> in my html 当我更新相机时,Raycaster 不会停留在中心 - Raycaster do not stays in center when i am updating camera Slick 轮播缺少 3 个资源。 我如何实现这些? - Missing 3 recources for the Slick carousel. How do I implement those? 使用递归交错两个数组(卡片组)......我能够在没有递归的情况下解决它,但想知道我做错了什么 - Interleave two arrays (card decks) using recursion... I was able to solve it without recursion but want to know what I am doing wrong 在光滑的旋转木马中,我希望我的中心滑块图像具有边距顶部 - In slick carousel, i want my center slider image to have a margin-top 如何使用Bootstrap创建响应式轮播嵌入式卡? - How do I create a responsive carousel embedded card using Bootstrap?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM