美文网首页
css-进阶-css开发技巧-Component Skill:组

css-进阶-css开发技巧-Component Skill:组

作者: 逸笛 | 来源:发表于2021-03-25 14:40 被阅读0次

下划线跟随导航栏

  • 要点:下划线跟随鼠标移动的导航栏
  • 场景:动态导航栏
  • 兼容:+
下划线跟随导航栏.gif
<div class="bruce flex-ct-x" data-title="下划线跟随导航栏">
    <ul class="underline-navbar">
        <li>Alibaba阿里巴巴</li>
        <li>Tencent腾讯</li>
        <li>Baidu百度</li>
        <li>Jingdong京东</li>
        <li>Ant蚂蚁金服</li>
        <li>Netease网易</li>
    </ul>
</div>
.underline-navbar {
    display: flex;
    li {
        position: relative;
        padding: 10px;
        cursor: pointer;
        font-size: 20px;
        color: #09f;
        transition: all 300ms;
        &::before {
            position: absolute;
            left: 100%;
            top: 0;
            border-bottom: 2px solid transparent;
            width: 0;
            height: 100%;
            content: "";
            transition: all 300ms;
        }
        &:active {
            background-color: #09f;
            color: #fff;
        }
        &:hover {
            &::before {
                left: 0;
                top: 0;
                z-index: -1;
                border-bottom-color: #09f;
                width: 100%;
                transition-delay: 100ms;
            }
            & + li::before {
                left: 0;
            }
        }
    }
}

气泡背景墙

  • 要点:不间断冒出气泡的背景墙
  • 场景:动态背景
  • 兼容:animation
图片.png
<div class="bruce" data-title="气泡背景墙">
    <ul class="bubble-bgwall">
        <li>Love</li>
        <li>Love</li>
        <li>Love</li>
        <li>Love</li>
        <li>Love</li>
        <li>Love</li>
        <li>Love</li>
        <li>Love</li>
        <li>Love</li>
        <li>Love</li>
    </ul>
</div>
.bruce {
    background-image: linear-gradient(270deg, #8146b4, #6990f6);
}
.bubble-bgwall {
    overflow: hidden;
    position: relative;
    margin: 0 auto;
    width: 100%;
    max-width: 1200px;
    height: 100%;
    li {
        display: flex;
        position: absolute;
        bottom: -200px;
        justify-content: center;
        align-items: center;
        border-radius: 10px;
        width: 50px;
        height: 50px;
        background-color: rgba(#fff, .15);
        color: #ccc;
        animation: bubble 15s infinite;
        &:nth-child(1) {
            left: 10%;
        }
        &:nth-child(2) {
            left: 20%;
            width: 90px;
            height: 90px;
            animation-duration: 7s;
            animation-delay: 2s;
        }
        &:nth-child(3) {
            left: 25%;
            animation-delay: 4s;
        }
        &:nth-child(4) {
            left: 40%;
            width: 60px;
            height: 60px;
            background-color: rgba(#fff, .3);
            animation-duration: 8s;
        }
        &:nth-child(5) {
            left: 70%;
        }
        &:nth-child(6) {
            left: 80%;
            width: 120px;
            height: 120px;
            background-color: rgba(#fff, .2);
            animation-delay: 3s;
        }
        &:nth-child(7) {
            left: 32%;
            width: 160px;
            height: 160px;
            animation-delay: 2s;
        }
        &:nth-child(8) {
            left: 55%;
            width: 40px;
            height: 40px;
            font-size: 12px;
            animation-duration: 15s;
            animation-delay: 4s;
        }
        &:nth-child(9) {
            left: 25%;
            width: 40px;
            height: 40px;
            background-color: rgba(#fff, .3);
            font-size: 12px;
            animation-duration: 12s;
            animation-delay: 2s;
        }
        &:nth-child(10) {
            left: 85%;
            width: 160px;
            height: 160px;
            animation-delay: 5s;
        }
    }
}
@keyframes bubble {
    0% {
        opacity: .5;
        transform: translateY(0) rotate(45deg);
    }
    25% {
        opacity: .75;
        transform: translateY(-400px) rotate(90deg);
    }
    50% {
        opacity: 1;
        transform: translateY(-600px) rotate(135deg);
    }
    100% {
        opacity: 0;
        transform: translateY(-1000px) rotate(180deg);
    }
}
换色器
  • 要点:通过拾色器改变图像色相的换色器
  • 场景:图片色彩变换
  • 兼容:mix-blend-mode
换色器.gif
<div class="bruce" data-title="图像换色器">
    <div class="color-changer">
        <input type="color" value="#ff6666">
        <img src="https://static.yangzw.vip/codepen/car.jpg">
    </div>
</div>

.color-changer {
    overflow: hidden;
    position: relative;
    height: 100%;
    input {
        position: absolute;
        width: 100%;
        height: 100%;
        mix-blend-mode: hue;
        cursor: pointer;
    }
    img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }
}

商城票券

  • 要点:边缘带孔和中间折痕的票劵
  • 场景:电影票代金券消费卡
  • 兼容:gradient
    图片.png
<div class="bruce flex-ct-x" data-title="商城打孔票券">
    <div class="mall-ticket">
        <h3>100元</h3>
        <p>网易考拉代金券</p>
    </div>
</div>
.mall-ticket {
    display: flex;
    position: relative;
    width: 300px;
    height: 100px;
    background: radial-gradient(circle at right top, transparent 10px, #f66 0) top left/100px 51% no-repeat,
        radial-gradient(circle at right bottom, transparent 10px, #f66 0) bottom left/100px 51% no-repeat,
        radial-gradient(circle at left top, transparent 10px, #ccc 0) top right/200px 51% no-repeat,
        radial-gradient(circle at left bottom, transparent 10px, #ccc 0) bottom right/200px 51% no-repeat;
    filter: drop-shadow(2px 2px 2px rgba(#fff, .2));
    line-height: 100px;
    text-align: center;
    color: #fff;
    &::before {
        position: absolute;
        left: 100px;
        top: 0;
        bottom: 0;
        margin: auto;
        border: 1px dashed #66f;
        height: 80px;
        content: "";
    }
    &::after {
        position: absolute;
        left: 100%;
        top: 0;
        width: 5px;
        height: 100%;
        background-image: linear-gradient(180deg, #ccc 5px, transparent 5px, transparent),
            radial-gradient(10px circle at 5px 10px, transparent 5px, #ccc 5px);
        background-size: 5px 15px;
        content: "";
    }
    h3 {
        width: 100px;
        font-size: 30px;
    }
    p {
        flex: 1;
        font-weight: bold;
        font-size: 18px;
    }
}
标签页
  • 要点:可切换内容的标签页
  • 场景:内容切换
  • 兼容:scroll-behavior
    动态边框.gif
<div class="bruce flex-ct-x" data-title="使用:hover控制悬浮边框">
    <div class="dynamic-border">iCSS</div>
</div>
.dynamic-border {
    width: 200px;
    height: 80px;
    background: linear-gradient(0, #f66 2px, #f66 2px) no-repeat left top/0 2px,
        linear-gradient(-90deg, #f66 2px, #f66 2px) no-repeat right top/2px 0,
        linear-gradient(-180deg, #f66 2px, #f66 2px) no-repeat right bottom/0 2px,
        linear-gradient(-270deg, #f66 2px, #f66 2px) no-repeat left bottom/2px 0;
    cursor: pointer;
    line-height: 80px;
    text-align: center;
    font-weight: bold;
    font-size: 50px;
    color: #f66;
    transition: all 300ms;
    &:hover {
        background-size: 100% 2px, 2px 100%, 100% 2px, 2px 100%;
    }
}

<meta name="source" content="lake">

自适应相册

<div class="bruce flex-ct-x" data-title="自适应相册">
        <ul class="response-album">
            <li class="item"><img src="https://static.yangzw.vip/codepen/ab-3.jpg"></li>
            <li class="item"><img src="https://static.yangzw.vip/codepen/ab-3.jpg"></li>
            <li class="item"><img src="https://static.yangzw.vip/codepen/ab-3.jpg"></li>
            <li class="item"><img src="https://static.yangzw.vip/codepen/ab-3.jpg"></li>
            <li class="item"><img src="https://static.yangzw.vip/codepen/ab-3.jpg"></li>
            <li class="item"><img src="https://static.yangzw.vip/codepen/ab-3.jpg"></li>
            <li class="item"><img src="https://static.yangzw.vip/codepen/ab-3.jpg"></li>
            <li class="item"><img src="https://static.yangzw.vip/codepen/ab-3.jpg"></li>
            <li class="item"><img src="https://static.yangzw.vip/codepen/ab-3.jpg"></li>
        </ul>
    </div>
@mixin square($count: 2) {
    $length: calc((100% - #{$count} * 10px) / #{$count});
    width: $length;
    height: $length;
}
.response-album {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    align-content: flex-start;
    padding: 5px;
    border: 1px solid #ccc;
    border-radius: 5px;
    width: 400px;
    height: 400px;
    li {
        display: flex;
        overflow: hidden;
        justify-content: center;
        margin: 5px;
        background-color: #f0f0f0;
        @include square(3);
    }
    img {
        width: 100%;
        height: 100%;

        object-fit: cover;
    }
}
// 一个元素
.item:only-child {
    border-radius: 10px;
    width: auto;
    max-width: 80%;
    height: auto;
    max-height: 80%;
}
// 两个元素
.item:first-child:nth-last-child(2),
.item:first-child:nth-last-child(2) ~ .item:nth-child(2) {
    @include square(2);
}
.item:first-child:nth-last-child(2) {
    border-radius: 10px 0 0 10px;
}
.item:first-child:nth-last-child(2) ~ .item:nth-child(2) {
    border-radius: 0 10px 10px 0;
}
// 三个元素
.item:first-child:nth-last-child(3),
.item:first-child:nth-last-child(3) ~ .item:nth-child(2),
.item:first-child:nth-last-child(3) ~ .item:nth-child(3) {
    @include square(2);
}
.item:first-child:nth-last-child(3) {
    border-top-left-radius: 10px;
}
.item:first-child:nth-last-child(3) ~ .item:nth-child(2) {
    border-top-right-radius: 10px;
}
.item:first-child:nth-last-child(3) ~ .item:nth-child(3) {
    border-bottom-left-radius: 10px;
}
// 四个元素
.item:first-child:nth-last-child(4),
.item:first-child:nth-last-child(4) ~ .item:nth-child(2),
.item:first-child:nth-last-child(4) ~ .item:nth-child(3),
.item:first-child:nth-last-child(4) ~ .item:nth-child(4) {
    @include square(2);
}
.item:first-child:nth-last-child(4) {
    border-top-left-radius: 10px;
}
.item:first-child:nth-last-child(4) ~ .item:nth-child(2) {
    border-top-right-radius: 10px;
}
.item:first-child:nth-last-child(4) ~ .item:nth-child(3) {
    border-bottom-left-radius: 10px;
}
.item:first-child:nth-last-child(4) ~ .item:nth-child(4) {
    border-bottom-right-radius: 10px;
}
// 五个元素
.item:first-child:nth-last-child(5) {
    border-top-left-radius: 10px;
}
.item:first-child:nth-last-child(5) ~ .item:nth-child(3) {
    border-top-right-radius: 10px;
}
.item:first-child:nth-last-child(5) ~ .item:nth-child(4) {
    border-bottom-left-radius: 10px;
}
// 六个元素
.item:first-child:nth-last-child(6) {
    border-top-left-radius: 10px;
}
.item:first-child:nth-last-child(6) ~ .item:nth-child(3) {
    border-top-right-radius: 10px;
}
.item:first-child:nth-last-child(6) ~ .item:nth-child(4) {
    border-bottom-left-radius: 10px;
}
.item:first-child:nth-last-child(6) ~ .item:nth-child(6) {
    border-bottom-right-radius: 10px;
}
// 七个元素
.item:first-child:nth-last-child(7) {
    border-top-left-radius: 10px;
}
.item:first-child:nth-last-child(7) ~ .item:nth-child(3) {
    border-top-right-radius: 10px;
}
.item:first-child:nth-last-child(7) ~ .item:nth-child(7) {
    border-bottom-left-radius: 10px;
}
// 八个元素
.item:first-child:nth-last-child(8) {
    border-top-left-radius: 10px;
}
.item:first-child:nth-last-child(8) ~ .item:nth-child(3) {
    border-top-right-radius: 10px;
}
.item:first-child:nth-last-child(8) ~ .item:nth-child(7) {
    border-bottom-left-radius: 10px;
}
// 九个元素
.item:first-child:nth-last-child(9) {
    border-top-left-radius: 10px;
}
.item:first-child:nth-last-child(9) ~ .item:nth-child(3) {
    border-top-right-radius: 10px;
}
.item:first-child:nth-last-child(9) ~ .item:nth-child(7) {
    border-bottom-left-radius: 10px;
}
.item:first-child:nth-last-child(9) ~ .item:nth-child(9) {
    border-bottom-right-radius: 10px;
}

相关文章

网友评论

      本文标题:css-进阶-css开发技巧-Component Skill:组

      本文链接:https://www.haomeiwen.com/subject/gbolhltx.html