跳至主要內容

轮播图

HeChuangJun约 442 字大约 1 分钟

轮播图

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>轮播图</title>
  <link rel="stylesheet" href="./iconfont/iconfont.css">
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    li {
      list-style: none;
    }
    /* 定位轮播图位置 */
    .banner {
      position: relative;/*子绝父相 */
      margin: 100px auto;
      width: 564px;
      height: 315px;
      /* background-color: pink; */
      overflow: hidden;/* 本来是横着3个图变为1个 */
    }

    /* 图片:去掉基线对齐使之居中 */
    .banner img {
      width: 564px;
      border-radius: 12px;
      vertical-align: middle;
    }

    .banner ul {
      display: flex;/* 3个图3行变一行 */
    }

    /* 箭头 */
    .banner .prev,
    .banner .next {
      /* 隐藏 */
      display: none;
      position: absolute;/*子绝父相 */
      top: 50%;/* 内容距离顶部50% */
      transform: translateY(-50%);/* 内容上移动50%,不影响布局 */

      width: 20px;
      height: 30px;
      background-color: rgba(0,0,0, 0.3);

      text-decoration: none;
      color: #fff;
      line-height: 30px;
    }

    /* 鼠标滑到banner区域,箭头要显示 display:block */
    .banner:hover .prev,
    .banner:hover .next {
      display: block;
    }
    /* 左右>< 分别设置 */
    .banner .prev {
      left: 0;
      border-radius: 0 15px 15px 0;
    }

    .banner .next {
      right: 0;
      border-radius: 15px 0 0 15px;
      text-align: center;
    }

    /* 圆点 */
    .banner ol {
      position: absolute;/*子绝父相 */
      bottom: 20px;
      left: 50%;/* 底部居中 */
      transform: translateX(-50%);
      height: 13px;
      background-color: rgba(255,255,255,0.3);

      display: flex;/* 一行多个点 */

      border-radius: 10px;
    }

    .banner ol li {
      margin: 3px;
      width: 8px;
      height: 8px;
      background-color: #fff;
      border-radius: 50%;
      cursor: pointer;
    }

    /* 橙色的li */
    .banner ol .active {
      background-color: #ff5000;
    }
  </style>
</head>
<body>
  <div class="banner">
    <!-- 图: ul > li -->
    <ul>
      <li><a href="#"><img src="./images/banner1.jpg" alt=""></a></li>
      <li><a href="#"><img src="./images/banner2.jpg" alt=""></a></li>
      <li><a href="#"><img src="./images/banner3.jpg" alt=""></a></li>
    </ul>
    <!-- 箭头 -->
    <!-- 上一张 prev -->
    <a href="#" class="prev">
      <i class="iconfont icon-zuoce"></i>
    </a>
    <!-- 下一张 next -->
    <a href="#" class="next">
      <i class="iconfont icon-youce"></i>
    </a>
    <!-- 圆点 -->
    <ol>
      <li></li>
      <li class="active"></li>
      <li></li>
    </ol>
  </div>
</body>
</html>