Home>

I was able to create a slideshow of images using only CSS, but I would like to implement a slideshow of sentences to explain the images.

I understand that it cannot be implemented with the same idea as the img tag, but is it possible to make only characters into a slide show with CSS?

Below is the HTML and CSS that created the slideshow with the img tag.
I would like to know what parts should be changed and how to create a slide show with only characters.


 <p>1</p>
 <p>2</p>
 <p>3</p>
 <p>4</p>
.slider4 {
  width: 60%;
  height: 60%;
  top: 50%;
  left: 50%;
  transform: translate (-50%, -50%);
  overflow: hidden;
  position: relative;
  user-select: none;
}
.slider4-img {
  position: absolute;
  object-fit: cover;
  width: 100%;
  height: 100%;
  left: 0;
  animation: slideshow4 14s linear infinite;
  opacity: 0;
}
@keyframes slideshow4 {
  0% {
    opacity: 0;
  }
  Ten%{
    opacity: 1;
  }
  20% {
    opacity: 1
  }
  30% {
    opacity: 0;
  }
  100% {
    opacity: 0;
  }
}
.slider4-img: nth-of-type (1) {animation-delay: 0s}
.slider4-img: nth-of-type (2) {animation-delay: 3.5s}
.slider4-img: nth-of-type (3) {animation-delay: 7s}
.slider4-img: nth-of-type (4) {animation-delay: 10.5s}
  • Answer # 1

    Fixed HTML class name and closing tag

    
     <p>1</p>
     <p>2</p>
     <p>3</p>
     <p>4</p>
    

    CSS is
    Since the character size and layout are unknown, a code example for centering with a character size that is half the height of the parent element.
    If the height of the parent element is specified as%, the height of the contents is 0, so it will be 0, so it must be in vw units.

    .slider4 {
      width: 60vw;
      height: 60vw;
      margin: 0 auto;
      overflow: hidden;
      position: relative;
      user-select: none;
      border: 1px solid gray;
    }
    .slider4-img {
      font-size: 30vw;
      line-height: 2;
      text-align: center;
      margin: 0;
      position: absolute;
      width: 100%;
      height: 100%;
      left: 0;
      animation: slideshow4 14s linear infinite;
      opacity: 0;
    }
    @keyframes slideshow4 {
      0% {
        opacity: 0;
      }
      Ten%{
        opacity: 1;
      }
      20% {
        opacity: 1
      }
      30% {
        opacity: 0;
      }
      100% {
        opacity: 0;
      }
    }
    .slider4-img: nth-of-type (1) {animation-delay: 0s}
    .slider4-img: nth-of-type (2) {animation-delay: 3.5s}
    .slider4-img: nth-of-type (3) {animation-delay: 7s}
    .slider4-img: nth-of-type (4) {animation-delay: 10.5s}

  • Answer # 2

    <p>1</p>
     <p>2</p>
     <p>3</p>
     <p>4</p>


    The closing tags for the three lines from the top above are full-width.
    Also, the class name seems to be wrong.

    <p>1</p>
     <p>2</p>
     <p>3</p>
     <p>4</p>


    If so, isn't it okay?