25.博客项目里面的总结

71 阅读1分钟
  1. 在写html的话遇到列表优先用ul li去做,更复合语义化,也更好处理。
  2. 行内元素通常外层包一个div,是为了更好处理位置。
  3. 下面是contact一段具有学习意义的代码
 <ul class="contact-container">
    <li>
        <a href="">
            <div class="icon weixin">
                <Icon type= "weixin" />
            </div>
            <span>fdafdasfdsa</span>
        </a>
        <div class="pop">
            <img src="https://st01.pic111222333.com/18071F/p06/%E5%9C%A8%E7%AA%97%E5%8F%A3%E7%9A%84%E9%87%91%E7%99%BC%5B23P%5D/01.jpg" alt="">
        </div>
    </li>
  </ul>

<style lang="less" scoped>
@import "~@/styles/var.less";
@import "~@/styles/global.less";
.contact-container {
    list-style: none;
    padding: 20px;
    margin: 0;
    color: @gray;
    // less 里面定义变量
    @itemHeight:30px;
     li {
        height:@itemHeight;
        line-height:@itemHeight;
        margin: 14px 0;
        position: relative;
        &:hover {
        // li 处于hover状态下选中 .pop元素
            .pop{
                transform: scaleY(1);
            }
        }
    }
    
    a {
        cursor: pointer;
        // 使用flex 将两个元素放到一排,这里就代替了浮动。
        display: flex;
        align-items: center;
        
        font-size: 14px;
    }
    
    .icon {
        font-size: 26px;
        width: 36px;
        &.weixin {
            font-size: 32px;
            // 调整微信图标的位置
            text-indent: -3px;
        }

    }

    .pop {
        position: absolute;
        left: 0;
        bottom: @itemHeight + 5px;
        padding: 10px 15px;
        background: #fff;
        border-radius: 5px;
        // 复合属性也不用全部写进去
        transform: scale(0);
        transform-origin: center bottom;
        transition: 0.3s;
        img {
            width: 150px;
            height: 150px;
        }
        // 下面是小尖尖的代码
        &::after{
            content:"";
            position: absolute;
            left: 50%;
            transform: translateX(-50%) rotate(45deg);
            width: 8px;
            height: 8px;
            background: #fff;
            bottom: -4px;
        }
    }
   
}