人生与戏

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

原文地址: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  人生与戏  阅读(203)  评论(0编辑  收藏  举报