描述

使用Flex布局+ transform-translate 布局实现 轮播图 CSS效果(无 JS效果-滚动,点击事件等)。

Code

        
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Carousel</title>
  <link rel="stylesheet" href="css.css">
</head>
<body>
<style>
  .carousel{
    width: 800px;
    margin: 100px auto;
    background-color: #212529;
    border-radius: 8px;
    padding: 32px 32px 32px 128px;
    display: flex;
    gap:128px;
    /*align-items: center;*/
    /* 这里打开这个配置可以不使用 translate 居中左右按钮*/
    position: relative;
  }

  /*img*/
  .carousel img{
    height: 200px;
    border-radius: 5px;
    /*图片缩放*/
    transform: scale(1.8);
    box-shadow: 2px -2px 5px rgb(248, 249, 250);
  }

  /*text*/
  .text{
    color: #ced4da;
    font-size: 16px;
  }
  .text-p{
    font-weight: 500;
    font-size: 20px;
    line-height: 1.5;
  }
  .text-author{
    font-size: 16px;
  }

  .text-job{
    font-size: 14px;
  }

  /*btn*/
  .btn{
    background-color:white;
    border: none;
    height: 40px;
    width: 40px;
    position: absolute;
    border-radius: 50%;
    box-shadow: 2px 1px 5px rgb(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .btn:hover{
    cursor: pointer;
  }



  .btn-icon{
    height: 24px;
    width: 24px;
    stroke: #212529;

  }

  .btn-left{
    left: -25px;
    top: 50%;
    transform: translate(0,-50%);
  }

  .btn-right{
    right: -25px;
    top: 50%;
    transform: translate(0,-50%);
  }

  /*dots*/
  .dots{
    position: absolute;
    left: 50%;
    transform: translate(-50%,32px);
    bottom: 0;
    display: flex;
    gap: 12px;
  }


  .dot{
    height: 18px;
    width: 18px;
    border-radius: 50%;
    background-color: white;
    border: 2px solid #212529;
    cursor: pointer;
  }

  .dot-fill{
    background-color: #212529;
  }
</style>
<div class="carousel">
  <img src="./Jinx.png" alt="Jinx">
  <div class="text">
    <p class="text-p">
      "Along with this series of meaningless crime, the law enforcement elite began to rise. Because she went barren, those law enforcement officers chased her called her —— "evil" (Jinx)"
    </p>
    <p class="text-author">
      Aleksanclr Nikolayerich Ostrovsky Jinx
    </p>
    <p class="text-job">
      League of Legends
    </p>
  </div>
  <button class="btn btn-left">
    <svg xmlns="http://www.w3.org/2000/svg" class="btn-icon" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
      <path stroke-linecap="round" stroke-linejoin="round" d="M15 19l-7-7 7-7" />
    </svg>
  </button>
  <button class="btn btn-right">
    <svg xmlns="http://www.w3.org/2000/svg" class="btn-icon" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
      <path stroke-linecap="round" stroke-linejoin="round" d="M9 5l7 7-7 7" />
    </svg>
  </button>
  <div class="dots">
    <button class="dot dot-fill"> </button>
    <button class="dot"> </button>
    <button class="dot"> </button>
    <button class="dot"> </button>
  </div>
</div>
</body>
</html>