72.纯 CSS 创作气泡填色的按钮特效

原文地址: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:;
padding:;
}
/* 设置所有元素的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:; }
/* 画出气泡,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:;
}
nav ul li span:nth-child(2) {
--n:;
}
nav ul li span:nth-child(3) {
--n:;
}
nav ul li span:nth-child(4) {
--n:;
}
nav ul li:hover{
color: black;
}
/* 鼠标移到按钮上 */
nav ul li:hover span {
transform: translateY(0) scale(2);
}
上一篇:iPhone系列设备媒体查询:


下一篇:Erlang进程的Link机制