【问题标题】:Slider next / prev. button滑块下一个/上一个。按钮
【发布时间】:2020-05-30 07:52:12
【问题描述】:

我想知道,是否可以将下一个和上一个按钮添加到我的主页滑块,该滑块仅使用 HTML 和 CSS 代码(没有任何 Javascript)。 如果是 - 我该如何管理?

https://codepen.io/michal-gambo/pen/zYGrMZo

我的网站是:autodielytatra.sk。 我的代码:

<div class="content" id="slider">
<figure><a href="https://www.autodielytatra.sk/sk/kategoria/nahradne-diely"><img class="hp-img-print" src="https://www.autodielytatra.sk/files/upload/homepage/images/homepage-1.jpg" style="margin-bottom: 10px;" /></a> <a href="https://www.autodielytatra.sk/sk/search?q=plast+%C5%BElt%C3%BD+domie%C5%A1ava%C4%8D"> <img class="hp-img-print" src="https://www.autodielytatra.sk/files/upload/homepage/images/homepage-2.jpg" /></a> <a href="https://www.autodielytatra.sk/sk/kategoria/akciovy-tovar"> <img class="hp-img-print" src="https://www.autodielytatra.sk/files/upload/homepage/images/homepage-3.jpg" /></a> <a href="https://www.autodielytatra.sk/sk/kategoria/nahradne-diely"> <img class="hp-img-print" src="https://www.autodielytatra.sk/files/upload/homepage/images/homepage-1.jpg" /></a></figure>
</div>

【问题讨论】:

    标签: html css button slider next


    【解决方案1】:

    “带有上一个和下一个按钮的纯 CSS 滑块”的快速 google 带来了很多东西,包括:

    https://codepen.io/AMKohn/pen/EKJHf

    鉴于您提供的信息,很难具体说明。

    滑块组件:

    <ul class="slides">
        <input type="radio" name="radio-btn" id="img-1" checked />
        <li class="slide-container">
            <div class="slide">
                <img src="http://farm9.staticflickr.com/8072/8346734966_f9cd7d0941_z.jpg" />
            </div>
            <div class="nav">
                <label for="img-6" class="prev">&#x2039;</label>
                <label for="img-2" class="next">&#x203a;</label>
            </div>
        </li>
    
        <input type="radio" name="radio-btn" id="img-2" />
        <li class="slide-container">
            <div class="slide">
              <img src="http://farm9.staticflickr.com/8504/8365873811_d32571df3d_z.jpg" />
            </div>
            <div class="nav">
                <label for="img-1" class="prev">&#x2039;</label>
                <label for="img-3" class="next">&#x203a;</label>
            </div>
        </li>
    
        <input type="radio" name="radio-btn" id="img-3" />
        <li class="slide-container">
            <div class="slide">
              <img src="http://farm9.staticflickr.com/8068/8250438572_d1a5917072_z.jpg" />
            </div>
            <div class="nav">
                <label for="img-2" class="prev">&#x2039;</label>
                <label for="img-4" class="next">&#x203a;</label>
            </div>
        </li>
    
        <input type="radio" name="radio-btn" id="img-4" />
        <li class="slide-container">
            <div class="slide">
              <img src="http://farm9.staticflickr.com/8061/8237246833_54d8fa37f0_z.jpg" />
            </div>
            <div class="nav">
                <label for="img-3" class="prev">&#x2039;</label>
                <label for="img-5" class="next">&#x203a;</label>
            </div>
        </li>
    
        <input type="radio" name="radio-btn" id="img-5" />
        <li class="slide-container">
            <div class="slide">
              <img src="http://farm9.staticflickr.com/8055/8098750623_66292a35c0_z.jpg" />
            </div>
            <div class="nav">
                <label for="img-4" class="prev">&#x2039;</label>
                <label for="img-6" class="next">&#x203a;</label>
            </div>
        </li>
    
        <input type="radio" name="radio-btn" id="img-6" />
        <li class="slide-container">
            <div class="slide">
              <img src="http://farm9.staticflickr.com/8195/8098750703_797e102da2_z.jpg" />
            </div>
            <div class="nav">
                <label for="img-5" class="prev">&#x2039;</label>
                <label for="img-1" class="next">&#x203a;</label>
            </div>
        </li>
    
        <li class="nav-dots">
          <label for="img-1" class="nav-dot" id="img-dot-1"></label>
          <label for="img-2" class="nav-dot" id="img-dot-2"></label>
          <label for="img-3" class="nav-dot" id="img-dot-3"></label>
          <label for="img-4" class="nav-dot" id="img-dot-4"></label>
          <label for="img-5" class="nav-dot" id="img-dot-5"></label>
          <label for="img-6" class="nav-dot" id="img-dot-6"></label>
        </li>
    </ul>
    

    还有 CSS:

    @import url(https://fonts.googleapis.com/css?family=Varela+Round);
    
    html, body { background: #333 url("https://codepen.io/images/classy_fabric.png"); }
    
    .slides {
        padding: 0;
        width: 609px;
        height: 420px;
        display: block;
        margin: 0 auto;
        position: relative;
    }
    
    .slides * {
        user-select: none;
        -ms-user-select: none;
        -moz-user-select: none;
        -khtml-user-select: none;
        -webkit-user-select: none;
        -webkit-touch-callout: none;
    }
    
    .slides input { display: none; }
    
    .slide-container { display: block; }
    
    .slide {
        top: 0;
        opacity: 0;
        width: 609px;
        height: 420px;
        display: block;
        position: absolute;
    
        transform: scale(0);
    
        transition: all .7s ease-in-out;
    }
    
    .slide img {
        width: 100%;
        height: 100%;
    }
    
    .nav label {
        width: 200px;
        height: 100%;
        display: none;
        position: absolute;
    
          opacity: 0;
        z-index: 9;
        cursor: pointer;
    
        transition: opacity .2s;
    
        color: #FFF;
        font-size: 156pt;
        text-align: center;
        line-height: 380px;
        font-family: "Varela Round", sans-serif;
        background-color: rgba(255, 255, 255, .3);
        text-shadow: 0px 0px 15px rgb(119, 119, 119);
    }
    
    .slide:hover + .nav label { opacity: 0.5; }
    
    .nav label:hover { opacity: 1; }
    
    .nav .next { right: 0; }
    
    input:checked + .slide-container  .slide {
        opacity: 1;
    
        transform: scale(1);
    
        transition: opacity 1s ease-in-out;
    }
    
    input:checked + .slide-container .nav label { display: block; }
    
    .nav-dots {
        width: 100%;
        bottom: 9px;
        height: 11px;
        display: block;
        position: absolute;
        text-align: center;
    }
    
    .nav-dots .nav-dot {
        top: -5px;
        width: 11px;
        height: 11px;
        margin: 0 4px;
        position: relative;
        border-radius: 100%;
        display: inline-block;
        background-color: rgba(0, 0, 0, 0.6);
    }
    
    .nav-dots .nav-dot:hover {
        cursor: pointer;
        background-color: rgba(0, 0, 0, 0.8);
    }
    
    input#img-1:checked ~ .nav-dots label#img-dot-1,
    input#img-2:checked ~ .nav-dots label#img-dot-2,
    input#img-3:checked ~ .nav-dots label#img-dot-3,
    input#img-4:checked ~ .nav-dots label#img-dot-4,
    input#img-5:checked ~ .nav-dots label#img-dot-5,
    input#img-6:checked ~ .nav-dots label#img-dot-6 {
        background: rgba(0, 0, 0, 0.8);
    }
    

    【讨论】:

    • 您只需从codepen.io/AMKohn/pen/EKJHf 复制粘贴代码 - 我几天前就已经找到了。我只需要知道是否可以将下一个上一个按钮添加到滑块,这是用我的 HTML 和 CSS 代码制作的。 HTML代码是我在问题中的代码,CSS在这里:
    • #slider { overflow: hidden;} #slider figure {position: relative;宽度:500%;边距:0;左:0;动画:15s 无限滑动; } #slider figure:hover { -webkit-animation-play-state: paused; -moz 动画播放状态:暂停; -o-动画播放状态:暂停;动画播放状态:暂停;光标:指针; } #slider figure img {float: left;宽度:20%;} @keyframes 滑块 { 0% {left: 0;} 20% {left: 0;} 25% {left: -100%;} 45% {left: -100%;} 50% {left : -200%;} 70% {左: -200%;} 75% {左: -300%;} 100% {左: -300%;} }
    • 您没有提供任何 html 或 css,只是一个指向外部网站的链接。这不是它的工作原理。您需要构建一个 codepen 并将其缩小到特定的滑块元素。如果您已经找到了可以解决您的问题的 codepen,为什么不将它合并到您的项目中呢?
    • 因为这不是我要照顾的。我有一个工作代码 - 完整的 HTML 代码在我的问题中,CSS 在上面的文章中。我需要在我的代码中添加下一个和上一个按钮,但我不知道是否可以实现这样的选项 - 我可以将 Javascript 放入其中,但我不知道如何使它一起工作
    • 如何添加(html、css、javascript)来添加下一个和上一个按钮选项???
    最近更新 更多