人生与戏

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

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

感想:过渡效果+xyz中一轴。

HTML code:

<nav>
    <ul>
        <li>
            home
            <span></span><span></span><span></span><span></span>
        </li>
    </ul>
</nav>

CSS code:

html, body,ul {
    margin: 0;
    padding: 0;
}
/* 设置所有元素的width、height包含border、padding、content
*{
    box-sizing: border-box;
}
 */
/* 设置body的子元素水平垂直居中 */
body {
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: black;
}
/* 设置按钮样式*/
nav ul {
    list-style-type: none;
}
nav ul li{
    /* 这里的相对定位为li绝对定位做准备 */
    position: relative;
    --c: goldenrod;
    color: var(--c);
    font-size: 16px;
    font-weight: bold;
    font-family: sans-serif;
    width: 12em;
    height: 3em;
    line-height: 3em;
    border: 0.3em solid var(--c);
    border-radius: 0.5em;
    text-align: center;
    letter-spacing: 0.1em;
    /* 外面的隐藏 */
    overflow: hidden;
    /* 显示层级降低,让文字优先显示 */
    z-index: 1;
    
}
/* 画出气泡,4个并列摆放 */
nav ul li span{
    position: absolute;
    left: calc((var(--n) - 1) * 25%);
    width: 25%;
    height: 100%;
    border-radius: 50%;
    background-color: var(--c);
    /* 定义Y轴位置 */
    transform: translateY(150%);
    /* 过渡属性 */
    transition: 0.5s;
    transition-delay: calc((var(--n) - 1) * 0.1s);
    /* 层级降低 */
    z-index: -1;
}
nav ul li span:nth-child(1) {
    --n: 1;
}
nav ul li span:nth-child(2) {
    --n: 2;
}
nav ul li span:nth-child(3) {
    --n: 3;
}
nav ul li span:nth-child(4) {
    --n: 4;
}
nav ul li:hover{
    color: black;
}
/* 鼠标移到按钮上 */
nav ul li:hover span {
    transform: translateY(0) scale(2);
}

 

posted on 2019-04-13 00:08  人生与戏  阅读(157)  评论(0编辑  收藏  举报