Positioning Taobao Carousel Picture-HTML+CSS Study Notes 20

effect

Insert picture description here

analysis

Insert picture description here

  1. Our class name for Big Box is: tb-promo Taobao ads
  2. Put a picture inside.
  3. Just use links for the left and right buttons. Left arrow prev right arrow next
  • Then the big box uses relative positioning, and the button uses absolute positioning.
  • How to do vertical centering?
    Take the left button as an example: left: 0 top: 50% margin-top: 15px
  1. The small dot ul on the bottom side continues to do it. The class name is promo-nav
  • The box at the bottom is still positioned absolutely, and the horizontal centering method is similar to the centering method of the button.
  • The dots are made with ul, and the dots are arranged in a row by floating.

Code

<!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>

Guess you like

Origin blog.csdn.net/weixin_45019830/article/details/107883485