css - react js 轮播和位置

标签 css reactjs

你好,我有一个旋转木马,但我在根据旋转木马的大小将图像 100% 保留时遇到问题

const ImageCarousel = () => (
  <CarouselProvider
  totalSlides={3}
  naturalSlideWidth={1}
  naturalSlideHeight={1.25}
  dragEnabled={false}
  touchEnabled={false}
  style={{ height: "500",position: "relative"}}
  >
    <Slider style={{maxHeight:'500px', width:'100%'}}>
      <Slide tag="a" index={0}>
        <Image  src="https://lorempixel.com/800/800/cats/0" />
      </Slide>
      <Slide tag="a" index={1}>
        <Image src="https://lorempixel.com/800/800/cats/1" />
      </Slide>
      <Slide tag="a" index={2}>
        <Image src="https://lorempixel.com/800/800/cats/2" />
      </Slide>
    </Slider>
    <Container style={{position: 'relative', backgroundColor:'#000'}}>
    <ButtonBack style={{position: 'absolute', transform: 'translate(-50%,-50%)', backgroundColor: 'transparent', border: 0}}><Icon fitted name='arrow right' size='big' /></ButtonBack>
    <ButtonNext style={{position: 'absolute', transform: 'translate(-50%,-50%)', backgroundColor: 'transparent', border: 0}}><Icon fitted name='arrow left' size='big' /></ButtonNext>
    </Container>
  </CarouselProvider>
);

现在我有这个:

enter image description here

最佳答案

您好,这个容器应该有一个宽度。

1- 在 ImageCarousel.js 的同一文件夹中创建一个名为“ImageCarousel.css”的 css 文件,并将代码放在下面:

.innterClass {
    height: 500px !important;
}

2-导入代码ImageCarousel.js

import "./ImageCarrousel.css";

3- 这是您的 ImageCarousel 组件中应该包含的代码:

const ImageCarousel = () => (
  <CarouselProvider
  totalSlides={3}
  naturalSlideWidth={1}
  naturalSlideHeight={1.25}
  dragEnabled={false}
  touchEnabled={false}
  style={{ height: "500",position: "relative"}}
  >
    <Slider style={{maxHeight:'500px'}}>
      <Slide innerClassName="innterClass" index={0}>
        <Image style={{objectFit: "cover"}}  src="https://lorempixel.com/800/800/cats/0" />
      </Slide>
      <Slide innerClassName="innterClass" index={1}>
        <Image style={{objectFit: "cover"}}  src="https://lorempixel.com/800/800/cats/1" />
      </Slide>
      <Slide innerClassName="innterClass" index={2}>
        <Image style={{objectFit: "cover"}}  src="https://lorempixel.com/800/800/cats/2" />
      </Slide>
    </Slider>
    <ButtonBack style={{position: 'absolute',top:'50%',left:'30%' ,transform: 'translate(-50%,-50%)', backgroundColor: 'transparent', border: 0}}><Icon fitted name='arrow right' size='big' /></ButtonBack>
    <ButtonNext style={{position: 'absolute', right:'30%', top: "50%", transform: 'translate(-50%,-50%)', backgroundColor: 'transparent', border: 0}}><Icon fitted name='arrow left' size='big' /></ButtonNext>

  </CarouselProvider>
);

关于css - react js 轮播和位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59354652/

相关文章:

css - Bootstrap 表单控制类不是自动换行标签

css - MVC : which CSS class implements Html. EditorFor() 方法?

html - Bootstrap : Align button adjacent to the textbox

javascript - 在特定元素的某个点将垂直滚动更改为水平滚动

reactjs - 部署到 Firebase 托管后,我的 React 项目无法正常工作

html - 将 div 中的两个元素垂直居中

javascript - 如何根据动态变化的背景颜色动态改变文字颜色

reactjs - Storybook JS 与 Enzyme 的集成测试 - 状态更改被覆盖

css - 将 css 与 react 一起使用

ReactJS - Redux Form - 如何根据单选字段元素有条件地显示/隐藏元素?