Home > Blockchain >  How can I use css to make a scroller like this?
How can I use css to make a scroller like this?

Time:09-08

how can i make a scroller like this? I don't know what's the name of this...

CodePudding user response:

Well this actually is a 'carousel'. If you are just beginning with development, I'd suggest you use bootstrap or semanticUI for carousel.

CodePudding user response:

If you want to do it with only HTML and CSS, then you must know that it's not as simple as you may think. it's a little tricky and confusing especially if you are a beginner like me.

here is an example by Anca Spatariu using only HTML and CSS.

.carousel {
    margin-left: 15%;
    margin-right: 15%;
}

ul.slides {
    display: block;
    position: relative;
    height: 600px;
    margin: 0;
    padding: 0;
    overflow: hidden;
    list-style: none;
}

.slides * {
    user-select: none;
    -ms-user-select: none;
    -moz-user-select: none;
    -khtml-user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

ul.slides input {
    display: none; 
}


.slide-container { 
    display: block; 
}

.slide-image {
    display: block;
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    opacity: 0;
    transition: all .7s ease-in-out;
}   

.slide-image img {
    width: auto;
    min-width: 100%;
    height: 100%;
}

.carousel-controls {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 999;
    font-size: 100px;
    line-height: 600px;
    color: #fff;
}

.carousel-controls label {
    display: none;
    position: absolute;
    padding: 0 20px;
    opacity: 0;
    transition: opacity .2s;
    cursor: pointer;
}

.slide-image:hover   .carousel-controls label{
    opacity: 0.5;
}

.carousel-controls label:hover {
    opacity: 1;
}

.carousel-controls .prev-slide {
    width: 49%;
    text-align: left;
    left: 0;
}

.carousel-controls .next-slide {
    width: 49%;
    text-align: right;
    right: 0;
}

.carousel-dots {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 20px;
    z-index: 999;
    text-align: center;
}

.carousel-dots .carousel-dot {
    display: inline-block;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background-color: #fff;
    opacity: 0.5;
    margin: 10px;
}

input:checked   .slide-container .slide-image {
    opacity: 1;
    transform: scale(1);
    transition: opacity 1s ease-in-out;
}

input:checked   .slide-container .carousel-controls label {
     display: block; 
}

input#img-1:checked ~ .carousel-dots label#img-dot-1,
input#img-2:checked ~ .carousel-dots label#img-dot-2,
input#img-3:checked ~ .carousel-dots label#img-dot-3,
input#img-4:checked ~ .carousel-dots label#img-dot-4,
input#img-5:checked ~ .carousel-dots label#img-dot-5,
input#img-6:checked ~ .carousel-dots label#img-dot-6 {
    opacity: 1;
}


input:checked   .slide-container .nav label { display: block; }
<div>
  <div >
    <ul >
      <input type="radio" name="radio-buttons" id="img-1" checked />
      <li >
        <div >
          <img src="https://upload.wikimedia.org/wikipedia/commons/9/9e/Timisoara_-_Regional_Business_Centre.jpg">
        </div>
        <div >
          <label for="img-3" >
            <span>&lsaquo;</span>
          </label>
          <label for="img-2" >
            <span>&rsaquo;</span>
          </label>
        </div>
      </li>
      <input type="radio" name="radio-buttons" id="img-2" />
      <li >
        <div >
          <img src="https://content.r9cdn.net/rimg/dimg/db/02/06b291e8-city-14912-171317ad83a.jpg?width=1750&height=1000&xhint=3040&yhint=2553&crop=true">
        </div>
        <div >
          <label for="img-1" >
            <span>&lsaquo;</span>
          </label>
          <label for="img-3" >
            <span>&rsaquo;</span>
          </label>
        </div>
      </li>
      <input type="radio" name="radio-buttons" id="img-3" />
      <li >
        <div >
          <img src="https://speakzeasy.files.wordpress.com/2015/05/twa_blogpic_timisoara-4415.jpg">
        </div>
        <div >
          <label for="img-2" >
            <span>&lsaquo;</span>
          </label>
          <label for="img-1" >
            <span>&rsaquo;</span>
          </label>
        </div>
      </li>
      <div >
        <label for="img-1"  id="img-dot-1"></label>
        <label for="img-2"  id="img-dot-2"></label>
        <label for="img-3"  id="img-dot-3"></label>
      </div>
    </ul>
  </div>
</div>

The better option will be learning javascript and building your own carousel. you can start learning here.

and here is another example with javascript

  • Related