欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
    源代码下载
    https://github.com/comehope/front-end-daily-challenges
    代码解读
    定义dom,容器中包含9个元素:
    <divclass="container">
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    </div>
    居中显示:
    body{
    margin:0;
    height:100vh;
    display:flex;
    align-items:center;
    justify-content:center;
    background-color:black;
    }
    定义容器尺寸:
    .container{
    width:30em;
    height:30em;
    font-size:10px;
    }
    用grid布局把9个子元素排列成3*3的网格状:
    .container{
    display:grid;
    grid-template-columns:repeat(3,1fr);
    }
    设置容器内子元素的样式,是通过伪元素来设置的:
    .containerspan{
    position:relative;
    }
    .containerspan::before,
    .containerspan::after
    {
    content:'';
    position:absolute;
    box-sizing:border-box;
    border-style:nonesolidsolidnone;
    border-width:1em;
    border-color:gold;
    width:100%;
    height:100%;
    }
    旋转容器,让它的尖端朝上:
    .container{
    transform:rotate(-135deg);
    }
    增加子元素尺寸由小到大变化的动画:
    .containerspan::before,
    .containerspan::after
    {
    animation:
    animate-scale1.6slinearinfinite;
    }
    @keyframesanimate-scale{
    from{
    width:1%;
    height:1%;
    }
    to{
    width:100%;
    height:100%;
    }
    }
    增加子元素边框色变化的动画:
    .containerspan::before,
    .containerspan::after
    {
    animation:
    animate-border-color1.6slinearinfinite,
    animate-scale1.6slinearinfinite;
    }
    @keyframesanimate-border-color{
    0%,25%{
    border-color:tomato;
    }
    50%,75%{
    border-color:gold;
    }
    100%{
    border-color:black;
    }
    }
    增加子元素边框宽度变化的动画:
    .containerspan::before,
    .containerspan::after
    {
    animation:
    animate-border-width1.6slinearinfinite,
    animate-border-color1.6slinearinfinite,
    animate-scale1.6slinearinfinite;
    }
    最后,让::after伪元素的动画时间慢半拍:
    .containerspan::after{
    animation-delay:-0.8s;
    }
    @keyframesanimate-border-width{
    0%,100%{
    border-width:0.1em;
    }
    25%{
    border-width:1.5em;
    }
    }

745211572-5b9ef45e8e966_articlex.gif




本文转载自中文网
 

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/css3-style/c57132.shtml