技术交流QQ群:1027579432,欢迎你的加入!

1.整体效果

1.png

2.案例分析

2.png

3.具体实现

  • 大盒子类的命名tb-promo,淘宝广告;
  • 里面放一张图片;
  • 左右两个按钮用链接就可以,左箭头prev,右箭头next;
  • 底侧小圆点用ul来实现,命名为promo-nav。

4.大盒子制作

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>综合案例之淘宝轮播图布局</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .tb-promo {
            /* 子绝父相 */
            position: relative;
            width: 520px;
            height: 280px;
            background-color: pink;
            margin: 100px auto;
        }
        
        .tb-promo img {
            width: 520px;
            height: 280px;
        }
    </style>
</head>

<body>
    <div class="tb-promo">
        <img src="./images/tb.jpg">
        <!-- 左侧按钮 -->
        <a href="#" class="prev">&lt;</a>
        <!-- 右侧按钮 -->
        <a href="#" class="next">&gt;</a>
    </div>
</body>

5.左侧箭头制作

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>综合案例之淘宝轮播图布局</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .tb-promo {
            /* 子绝父相 */
            position: relative;
            width: 520px;
            height: 280px;
            background-color: pink;
            margin: 100px auto;
        }

        .tb-promo img {
            width: 520px;
            height: 280px;
        }

        /* 左侧按钮 */
        .prev {
            /* 加了绝对定位的盒子,可以直接设置宽度和高度 */
            position: absolute; 
            left: 0;
            /* 让绝对定位的盒子垂直居中 */
            top: 50%; 
            margin-top: -15px; 
            width: 20px; 
            height: 30px; 
            background: rgba(0, 0, 0, .3); 
            text-align: center; 
            line-height: 30px; 
            color: #fff; 
            text-decoration: none; 
            /* 圆角边框 */
            border-top-right-radius: 15px;
            border-bottom-right-radius: 15px;
        }
    </style>
</head>

<body>
    <div class="tb-promo">
        <img src="./images/tb.jpg">
        <!-- 左侧按钮 -->
        <a href="#" class="prev">&lt;</a>
    </div>
</body>

6.右侧箭头制作

  • 因为左右两侧箭头中CSS的代码有很多是相同的,因此建议使用并集选择器可以将重复的代码写在一起,给代码解耦!
  • 注意:如果一个盒子既有left属性也有right属性,则默认会执行left属性。同理,top和bottom属性同时存在,会执行top属性!!!
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>综合案例之淘宝轮播图布局</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .tb-promo {
            /* 子绝父相 */
            position: relative;
            width: 520px;
            height: 280px;
            background-color: pink;
            margin: 100px auto;
        }

        .tb-promo img {
            width: 520px;
            height: 280px;
        }

        /* 并集选择器可以集体声明相同的样式 */

        .prev,
        .next {
            position: absolute;
            /* 让绝对定位的盒子垂直居中 */
            top: 50%;
            margin-top: -15px;
            width: 20px;
            height: 30px;
            background: rgba(0, 0, 0, .3);
            text-align: center;
            line-height: 30px;
            color: #fff;
            text-decoration: none;
        }

        /* 左侧按钮 */

        .prev {
            /* 加了绝对定位的盒子,可以直接设置宽度和高度 */
            /* position: absolute; */
            left: 0;
            /* 让绝对定位的盒子垂直居中 */
            /* top: 50%; */
            /* margin-top: -15px; */
            /* width: 20px; */
            /* height: 30px; */
            /* background: rgba(0, 0, 0, .3); */
            /* text-align: center; */
            /* line-height: 30px; */
            /* color: #fff; */
            /* text-decoration: none; */
            /* 圆角边框 */
            border-top-right-radius: 15px;
            border-bottom-right-radius: 15px;
        }

        /* 右侧按钮 */

        .next {
            /* 加了绝对定位的盒子,可以直接设置宽度和高度 */
            /* position: absolute; */
            /* 如果一个盒子既有left属性也有right属性,则默认会执行left属性。同理,top和bottom属性同时存在,会执行top属性!!!*/
            right: 0;
            /* 让绝对定位的盒子垂直居中 */
            /* top: 50%;
            margin-top: -15px;
            width: 20px;
            height: 30px;
            background: rgba(0, 0, 0, .3);
            text-align: center;
            line-height: 30px;
            color: #fff;
            text-decoration: none; */
            /* 圆角边框 */
            border-top-left-radius: 15px;
            border-bottom-left-radius: 15px;
        }
    </style>
</head>

<body>
    <div class="tb-promo">
        <img src="./images/tb.jpg">
        <!-- 左侧按钮 -->
        <a href="#" class="prev">&lt;</a>
        <!-- 右侧按钮 -->
        <a href="#" class="next">&gt;</a>
    </div>
</body>

</html>

7.小圆点模块制作

li {
        list-style: none;
    }
    
.promo-nav {
            position: absolute;
            bottom: 15px;
            left: 50%;
            margin-left: -35px;
            background: rgba(255, 255, 255, .3);
            width: 70px;
            height: 13px;
            border-radius: 7px;
        }

.promo-nav li {
            float: left;
            width: 8px;
            height: 8px;
            background-color: #fff;
            <!--小圆点的做法-->
            border-radius: 50%;
            margin: 3px;
        }

/* 不要忘记选择器权重的问题 */
.promo-nav .selected {
    background-color: #ff5000;
}
        
<body>
    <div class="tb-promo">
        <img src="./images/tb.jpg">
        <!-- 左侧按钮 -->
        <a href="#" class="prev">&lt;</a>
        <!-- 右侧按钮 -->
        <a href="#" class="next">&gt;</a>
        <!-- 小圆点模块 -->
        <ul class="promo-nav">
            <li class="selected"></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
    </div>
</body>

8.资料下载