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

本文介绍如何仅使用CSS实现一对能在黑暗中眨眼的眼睛效果。通过巧妙设置HTML结构与CSS样式,包括定位、边框、动画等属性,使两个圆形元素模仿眼睛进行眨眼动作。适合初学者学习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: 0;
    padding: 0;
}
/* 设置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: 0;
    border-radius: 50% 0;
    /* 使双眼向内聚拢 */
    transform: rotate(25deg);
}
.eyes .right {
    right : 0;
    border-radius: 0 50%;
    transform: rotate(-25deg);
}
/* 定义眨眼的动画 */
@keyframes blink{
    40%, 60%{
        border-width: 0 5em;
    }
    50% {
        border-width: 0 7.5em;
    }
}

 

posted on 2019-03-29 11:22 人生与戏 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/FlyingLiao/p/10620121.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值