定位之淘宝轮播图——HTML+CSS学习笔记20

效果

在这里插入图片描述

分析

在这里插入图片描述

  1. 大盒子我们类名为: tb-promo 淘宝广告
  2. 里面先放一张图片。
  3. 左右两个按钮 用链接就好了。 左箭头 prev 右箭头 next
  • 那么大盒子采用相对定位,按钮采用绝对定位。
  • 垂直居中如何做到?
    以左边按钮为例子:left:0 top:50% margin-top:15px
  1. 底侧小圆点ul 继续做。 类名为 promo-nav
  • 底部的这个盒子依旧绝对定位,水平居中方式类似于按钮的居中方式。
  • 圆点利用ul做,通过浮动使得圆点排在一行。

代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
     
     
            margin: 0;
            padding: 0;
        }
    li {
     
     
        list-style: none;       
    }
    .tb-promo {
     
     
        position: relative;
        width: 520px;
        height: 280px;
        background-color: pink;
        /* 这里是相对定位,没有脱离标准流 可以用这种方法水平居中*/
        margin: 100px auto;
    }
    .tb-promo img {
     
     
        width: 520px;
        height: 280px;
    }
    .next,
    .prev {
     
     
        /* 子绝父相 */
        position: absolute;
        /* 绝对定位设置垂直居中 */
        top: 50%;
        margin-top: -15px;
        /* 是定位,可以设置宽度高度,与浮动类似 */
        width: 20px;
        height: 30px;
        background-color: rgba(0, 0, 0, .3);
        color:white;
        text-align: center;
        line-height: 30px;
        text-decoration: none;
        
    }
    .prev {
     
     
        left: 0px;
        border-top-right-radius: 15px;
        border-bottom-right-radius: 15px;
    }
    .next {
     
     
        right: 0px;
        border-top-left-radius: 15px;
        border-bottom-left-radius: 15px;
    }
    .promo-nav {
     
     
        position: absolute;
        /* 绝对定位居中方式 */
        bottom: 15px;
        left: 50%;
        margin-left: -35px;
        width: 70px;
        height: 13px;
        background-color: rgba(255, 255, 255, .3);
        border-radius: 7px;
    }
    .promo-nav li {
     
     
        float:left;
        width: 8px;
        height: 8px;
        background-color: white;
        border-radius: 50%;
        margin: 3px;
    }
</style>
<body>
    <div class="tb-promo">
        <img src="pic.jpg" alt="图片">
        <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>
</html>

猜你喜欢

转载自blog.csdn.net/weixin_45019830/article/details/107883485