57.纯 CSS 创作一双黑暗中的眼睛

时间:2023-03-09 01:20:14
57.纯 CSS 创作一双黑暗中的眼睛

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

感想:原来边框还能这样玩--》做会眨眼的眼睛

HTML code:

<div class="eyes">
<span class="left"></span>
<span class="right"></span>
</div>

CSS  code:

html, body {
margin:;
padding:;
}
/* 设置body的子元素水平垂直居中 */
body{
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: black;
}
/* 设置容器尺寸 */
.eyes{
position: relative;
width: 40em;
height: 10em;
/* border: 1px solid white; */
font-size: 12px;
}
.eyes > * {
/* 设置宽高包含内边距/边框和内容 */
box-sizing: border-box;
position: absolute;
width: 15em;
height: 10em;
border: solid white;
/* 画眼球 */
border-width: 0 5em;
animation: blink 2s linear infinite;
}
.eyes .left{
left:;
border-radius: 50% 0;
/* 使双眼向内聚拢 */
transform: rotate(25deg);
}
.eyes .right {
right :;
border-radius: 0 50%;
transform: rotate(-25deg);
}
/* 定义眨眼的动画 */
@keyframes blink{
40%, 60%{
border-width: 0 5em;
}
50% {
border-width: 0 7.5em;
}
}