欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
    源代码下载
    https://github.com/comehope/front-end-daily-challenges
    代码解读
    定义dom,容器中有2个子元素,.envelope代表伞盖,.basket代表吊篮:
    <figureclass="balloon">
    <divclass="envelope">
    <span></span>
    <span></span>
    </div>
    <divclass="basket">
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    </div>
    </figure>
    居中显示:
    body{
    margin:0;
    height:100vh;
    display:flex;
    align-items:center;
    justify-content:center;
    background:linear-gradient(deepskyblue,skyblue,lightblue20%);
    }
    定义容器的尺寸,子元素.envelope和.basket纵向居中布局:
    .balloon{
    width:12em;
    height:19em;
    font-size:16px;
    display:flex;
    flex-direction:column;
    align-items:center;
    }
    先画伞盖。
    定义伞盖的尺寸:
    .envelope{
    position:relative;
    width:inherit;
    height:16em;
    }
    伞盖的形状是上端为球形,下端为圆锥形,在二维平面中,圆锥在平面的投影为等腰三角形,所以我们先在上部画一个圆,再在下部画一个三角形。
    先画上部的圆:
    .envelopespan{
    position:absolute;
    width:inherit;
    height:12em;
    border-radius:50%;
    color:orange;
    background-color:currentColor;
    }
    再用伪元素画出下部的等腰三角形:
    .envelopespan::before{
    content:'';
    position:absolute;
    width:0;
    height:0;
    border-width:10em5.5em05.5em;
    border-style:solid;
    border-color:currentColortransparenttransparenttransparent;
    left:calc(50%-5.5em);
    top:8.45em;
    }
    .envelope下共有2个<span>元素,让第2个<span>变形、变色,使伞盖形成竖条纹的花纹:
    .envelopespan:nth-child(2){
    transform:scaleX(0.4);
    filter:brightness(0.85)contrast(1.4);
    }
    隐藏.envelope容器外的部分,削掉三角形最下面的尖角:
    .envelope{
    overflow:hidden;
    }
    至此,伞盖完成,接下来画吊篮。
    定义吊篮的尺寸:
    .basket{
    position:relative;
    width:2em;
    height:3em;
    }
    用::before伪元素画出篮子:
    .basket::before{
    content:'';
    position:absolute;
    width:inherit;
    height:1.6em;
    background-color:peru;
    bottom:0;
    border-radius:000.5em0.5em;
    }
    用::after伪元素画出篮子的顶边:
    .basket::after{
    content:'';
    position:absolute;
    width:105%;
    height:0.3em;
    background-color:saddlebrown;
    left:calc((100%-105%)/2);
    top:1.3em;
    border-radius:0.3em;
    }
    .basket下共有4个<span>元素,代表4根缆绳,设置它们的样式为竖细线:
    .basketspan{
    position:absolute;
    width:0.1em;
    height:1.5em;
    background-color:burlywood;
    }
    定位缆绳,并倾斜不同的角度:
    .basketspan{
    left:calc((var(--n)-1)*0.6em);
    transform-origin:bottom;
    transform:rotate(calc(var(--r)*7deg));
    }
    .basketspan:nth-child(1){--n:1;--r:-2;}
    .basketspan:nth-child(2){--n:2;--r:-1;}
    .basketspan:nth-child(3){--n:3;--r:1;}
    .basketspan:nth-child(4){--n:4;--r:2;}
    最后,增加热气球微微浮动的动画效果:
    .balloon{
    animation:drift2sinfinitealternate;
    }
    @keyframesdrift{
    to{
    transform:translateY(-5%);
    }
    }






本文转载自中文网
 

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