人生与戏

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

原文地址:https://segmentfault.com/a/1190000015192218

感想: 伪元素作为背景变化。

HTML code:

<nav>
    <ul>
        <li>
            <span>h</span>
            <span>o</span>
            <span>m</span>
            <span>e</span>
        </li>
        <li>
            <span>p</span>
            <span>r</span>
            <span>o</span>
            <span>d</span>
            <span>u</span>
            <span>c</span>
            <span>t</span>
            <span>s</span>
        </li>
        <li>
            <span>s</span>
            <span>e</span>
            <span>v</span>
            <span>i</span>
            <span>c</span>
            <span>e</span>
            <span>s</span>
        </li>
        <li>
            <span>c</span>
            <span>o</span>
            <span>n</span>
            <span>t</span>
            <span>a</span>
            <span>c</span>
            <span>t</span>
        </li>
    </ul>
</nav>

CSS code:

html, body,ul {
    margin: 0;
    padding: 0;
}
ul{
    list-style: none;
}
body{
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(to right bottom, dimgray, black);
}
/* 单词左侧加一条鼠标悬停时变亮的竖线 */
li{
    margin: 1em 0;
    padding-left: 2em;
    border: 2px solid transparent;
    border-left-color: silver;
    text-align: center;
    transition: 50ms;
}
li:hover{
    border-left-color: white;
}

li:hover span{
    color: #333;
    transition-delay: calc(80ms * var(--n) + 10ms);
}
li span{
    position: relative;
    color: white;
    font-size: 50px;
    font-family: monospace;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    /* 定义过渡所花时间 */
    transition: 500ms;
}
li span::before{
    position: absolute;
    content:'';
    height: 100%;
    width: 0;
    z-index: -1;
    transition: 500ms;
}
li:hover span::before{
    width: 70%;
    transform: rotate(-25deg);
    background: white;
    transition-delay: calc(80ms * var(--n));
}
li span:nth-child(1) {
    --n: 1;
}
li span:nth-child(2) {
    --n: 2;
}
li span:nth-child(3) {
    --n: 3;
}
li span:nth-child(4) {
    --n: 4;
}
li span:nth-child(5) {
    --n: 5;
}
li span:nth-child(6) {
    --n: 6;
}
li span:nth-child(7) {
    --n: 7;
}
li span:nth-child(8) {
    --n: 8;
}

 

posted on 2019-02-28 16:55  人生与戏  阅读(191)  评论(0编辑  收藏  举报