无法用点自定义 react-bootstrap 轮播

我正在使用react-bootstrap它对我来说很好用的旋转木马,但我唯一不能定制的是:

  • 箭头

  • 指标线

我只想将箭头颜色从白色透明度更改为橙色,我希望用点替换线条。

       <Carousel className="home-slider">

          {

            LIST.map((classitem) => 

              <Carousel.Item className="home-slider-item">

                  <img

                    className="slider-item"

                    src={classitem.classpic[0]}

                    alt="Slide"

                  />

                  <Carousel.Caption className="slider-item-content">

                    <h3>{classitem.title}</h3>

                    <p>{classitem.desc}</p>

                    <div className="slider-button">

                    <BlueButton link_href={`/classdetails?id=${classitem.id}`} text="Discover" />         

                    </div>

                    </Carousel.Caption>

                </Carousel.Item>

              )            

          }

      </Carousel>


CSS 是:


.home-slider {

    width: 70%;

    margin-left: 20%;

    margin-right: 10%;

}


.home-slider h3{

    font-size: 24px;

    color: white;

    text-align: left;

    font-family: Fredoka One;

}


.home-slider p{

    font-size: 16px;

    color: white;

    font-weight: normal;

    text-align: left;

    font-family: Source Sans Pro;

}


.slider-item {

    width: 100%;

    height: 400px;

    border-radius: 20px;

    object-fit: cover;

}


.slider-item-content {

    margin-bottom: 40px;

    border-radius: 20px;

    background-color: #ff725590;

    padding: 10px 10px 10px 10px;

}


.slider-button {

    text-align: left;

    margin-top: 50px;;

}

这就是我所拥有的:

http://img2.mukewang.com/6389b1cc0001467d06480300.jpg

关于如何将线更改为点并更改箭头颜色的任何想法?



莫回无
浏览 178回答 5
5回答

jeck猫

使用 owl carousel 是最好的选择,它支持几乎所有的浏览器,有很多选项我建议 OwlC 而不是 BS 滑块。一些例子:`https://codepen.io/tag/owl%20carousel/`

慕少森

将以下内容添加到您导入到项目中的 css 文件中就足够了。如果你运行应用程序并构建它,你可以通过查看标签轻松地使用 css 来完成它。.carousel .carousel-indicators button {&nbsp; background-color: #3c9feb;&nbsp; border: none;&nbsp; border-radius: 50%;&nbsp; width: 10px;&nbsp; height: 10px;}

蝴蝶不菲

owl carousel 没有回答有关 React-bootstrap Carousel 的问题。要在 React-bootstrap 的 Carousel 组件中呈现自定义幻灯片和指示器的动态数组,您需要做很多事情。从他们网站上的说明开始,我会做这样的事情:function CustomReactCarousel(props) {&nbsp; const { items } = props;&nbsp; const [index, setIndex] = useState(0);&nbsp; const handleSelect = (selectedIndex, e) => {&nbsp; &nbsp; //React-bootstrap carousel has an indexing error that causes blank slides&nbsp;&nbsp; &nbsp; //(probably happens when you customize it).&nbsp;&nbsp; &nbsp; //You need to account for it in this callback...&nbsp; &nbsp; //adjust index to 0 if selectedIndex is greater than index of last slide or&nbsp;&nbsp; &nbsp; //it is less than zero&nbsp; &nbsp; //remember slide indexes are zero-based&nbsp; &nbsp; if (selectedIndex >= items.length || selectedIndex < 0 ){&nbsp; &nbsp; &nbsp; &nbsp; setIndex(0);&nbsp; &nbsp; } else if (selectedIndex !== index) {&nbsp; &nbsp; &nbsp; &nbsp; setIndex(selectedIndex);&nbsp; &nbsp; }&nbsp; };&nbsp; return (&nbsp; &nbsp; <Carousel&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; activeIndex={index}&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; onSelect={handleSelect}&nbsp; &nbsp; &nbsp; &nbsp; controls={true}&nbsp; &nbsp; &nbsp; &nbsp; nextIcon={<span aria-hidden="true" className="fas fa-chevron-right fa-3x customNextClass"/>}&nbsp; &nbsp; &nbsp; &nbsp; prevIcon={<span aria-hidden="true" className="fas fa-chevron-left fa-3x customPrevClass"/>}&nbsp; &nbsp; &nbsp; &nbsp; indicators={false}&nbsp; &nbsp; &nbsp; &nbsp; interval={5000}&nbsp; &nbsp; >&nbsp; &nbsp; &nbsp; &nbsp; {Items.map((item,itemIndex) => {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <Carousel.Item className={"home-slider-item "+ item.itemSliderClass}>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <img&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; className={"slider-item "+ item.itemImgClass}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; src={item.classpic[0]}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alt="Slide"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <Carousel.Caption className={"slider-item-content "+ item.itemCaptionContent}>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <h3>{item.title}</h3>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <p>{item.desc}</p>&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </Carousel.Caption>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </Carousel.Item>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;)&nbsp; &nbsp; &nbsp; &nbsp; })}&nbsp; &nbsp; &nbsp; &nbsp; <ol className="carousel-indicators">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {items.map((item, itemIndex) => {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return (&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <li&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; key={index}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; onClick={() => this.handleCarouselSlide(itemIndex,null)}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; className={((itemIndex === index) ? "active" : "")+" "+item.itemIndicatorClass}/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;})}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </ol>&nbsp; &nbsp; </Carousel>&nbsp; );}render(<CustomReactCarousel />);笔记:我把你LIST的改成items了道具。我假设它是您想要在轮播上显示的自定义对象列表。我创建了一个函数,如 React 说明中所示,以容纳回调等。确保indicators={false}在添加自己的指标列表时进行。否则,该组件将生成两个列表。请注意如何根据自定义指标列表中的选择索引手动设置“活动”类。自定义React-boostrap Carousel时出现的array indexing error参见handleSelect回调函数中的注释。上面的 handleSelect 回调应该可以修复该错误。如果您想设置指示器按钮的样式,Beu 是正确的。通过引用它们的.carousel-indicators类来设置它们的样式(无论您是否自定义)。请注意,<ol className="carousel-indicators">即使在上面显示的自定义指标列表中,也会保留此类名称。.carousel-indicators li {&nbsp; background-color: gray;&nbsp; border-radius: 50%;&nbsp; width: 8px;&nbsp; height: 8px;}.carousel-indicators li.active {&nbsp; background-color: #333;&nbsp; width: 12px !important;&nbsp; height: 12px !important;}除了新的自定义上一个和下一个图标及其在此处执行的本地样式之外,您还可以在 css 中设置它们的区域样式。为此,请参考.carousel-control-prev和.carousel-control-next类:.carousel-control-prev {&nbsp; &nbsp; width: 10%;&nbsp; &nbsp; margin-bottom: 30px;}.carousel-control-next {&nbsp; &nbsp; width: 10%;&nbsp; &nbsp; margin-bottom: 30px;}

慕娘9325324

您可以自定义css来获取它.carousel-indicators li {&nbsp; background-color: gray;&nbsp; border-radius: 50%;&nbsp; width: 8px;&nbsp; height: 8px;}.carousel-indicators li.active {&nbsp; background-color: #333;&nbsp; width: 12px !important;&nbsp; height: 12px !important;}

千巷猫影

对于仍然需要答案的任何人,我将整个轮播组件放在一个 div 中,并使用 is CSS 来设置指示器(按钮)的样式,对于箭头,我没有答案。我正在使用 react-boostrap v2.0.carouselDiv >div >div >button{&nbsp; &nbsp; background-color: black!important;&nbsp; &nbsp; border-radius: 50% !important;&nbsp; &nbsp; height: 12px!important;&nbsp; &nbsp; width: 12px!important;}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript