温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

使用css3怎么实现一个宠物小鸡

发布时间:2021-05-27 16:24:02 阅读:236 作者:Leah 栏目:web开发
前端开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

今天就跟大家聊聊有关使用css3怎么实现一个宠物小鸡,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

<body>
    <div class="content">
        <!-- 天上的云 -->
        <div class="cloud">
            <div class="content"></div>
        </div>
        <!--鸡冠-->
        <div class="crest"></div>
        <!--翅膀-->
        <div class="hand"></div>
        <!-- 宠物小鸡body -->
        <div class="egg">
            <!--眼睛-->
            <div class="eye"></div>
            <!--腮红-->
            <div class="blush"></div>
            <!--嘴-->
            <div class="mouth"></div>
            <!--脚-->
            <div class="feet"></div>
        </div>

    </div>
</body>

接下来是css设置样式:

先设置整体的背景色,使用的是线性渐变linear-gradient,设置蓝天色和草地色,并设置让元素居中。

.content {
        width100%;
        height800px;
        backgroundlinear-gradient(rgb(17022725360%rgb(14921912680px);
        display: flex;
        justify-content: center;
        align-items: center;
        }

天上的云:先给一定的宽高和背景色,使用border-radius设置边框圆角效果,只设置左上和右上。效果如下:

 border-radius: 100% 100% 0 0;

使用css3怎么实现一个宠物小鸡

在使用::before和::after伪元素画出一朵完整的云:

.content::before,
 .content::after {
                content'';
                position: absolute;
                bottom0;
            }
  .content::before {
                width40px;
                height40px;
                background: currentColor;
                left: -20px;
                border-radius100% 100% 0 100%;
            }
   .content::after {
                width35px;
                height30px;
                background: currentColor;
                right: -20px;
                border-radius100% 100% 100% 0;
            }

然后使用阴影在画出两朵云

使用css3怎么实现一个宠物小鸡

.content,
.content::before,
.content::after {
                box-shadow: 
                -200px 50px 0 -5px rgb(191232252),
                 200px 60px 0 10px rgb(191233253);
            }

使用css3怎么实现一个宠物小鸡

云朵实现了。

接下来是宠物小鸡,先把身体写出来,同样用border-radius设置边框圆角效果,画出鸡蛋的模样,设置背景色,并使用box-shadow设置向内的阴影。

.egg {
            width220px;
            height260px;
            border-radius100%;
            backgroundlinear-gradient(rgb(25424924960%,rgb(221213213));
            position: absolute;
            display: flex;
            flex-direction: column;
            align-items: center;
            box-shadow0 -10px 10px 3px rgba(211194194,0.4) inset;
}

使用css3怎么实现一个宠物小鸡

鸡冠和云朵的写法差不多

.crest {
            position: relative;
            top: -17%;
            width30px;
            height25px;
            backgroundrgb(2331919);
            border-radius50% 100% 20% 20%;
        }
  .crest::before,
  .crest::after {
            content'';
            position: absolute;
            bottom0; 
            width20px; 
            backgroundrgb(2331919);
        }
  .crest::before {
            left: -5px;
            height20px;
            border-radius100% 50% 0 20%;
        }
  .crest::after {
            right: -15px;
            height15px;
            backgroundrgb(2331919);
            border-radius20% 200% 20% 30%;
        }

眼睛,翅膀,腮红,分别用伪元素左右定位设置大小即可实现。嘴部使用transform旋转45&deg;并使用线性渐变设置鸡嘴的阴影效果。

全部css代码如下(我安装了sass插件,所以是scss的写法):

body {
    margin0;
    width100%;
    height100%;
    >.content {
        width100%;
        height800px;
        backgroundlinear-gradient(rgb(17022725360%rgb(14921912680px);
        display: flex;
        justify-content: center;
        align-items: center;
        >.cloud {
            position: absolute;
            top5%;
            colorrgb(216242254);
            >.content {
                width50px;
                height50px;
                background: currentColor;
                border-radius100% 100% 0 0;
            }
            >.content::before,
            >.content::after {
                content'';
                position: absolute;
                bottom0;
            }
            >.content::before {
                width40px;
                height40px;
                background: currentColor;
                left: -20px;
                border-radius100% 100% 0 100%;
            }
            >.content::after {
                width35px;
                height30px;
                background: currentColor;
                right: -20px;
                border-radius100% 100% 100% 0;
            } 
            >.content,
            .content::before,
            .content::after {
                box-shadow: -200px 50px 0 -5px rgb(191232252),
                             200px 60px 0 10px rgb(191233253);
            }
        }
        >.egg {
            width220px;
            height260px;
            border-radius100%;
            backgroundlinear-gradient(rgb(25424924960%,rgb(221213213));
            position: absolute;
            display: flex;
            flex-direction: column;
            align-items: center;
            box-shadow0 -10px 10px 3px rgba(211194194,0.4) inset;
            >.eye::before,
            .eye::after {
                content'';
                position: absolute;
                top15%;
                width12px;
                height28px;
                border-radius100%;
                backgroundradial-gradient(white 1pxrgb(5756575%);
            }
            > .eye::before{
                left28%;
            }
            >.eye::after {
                right28%;
            }
            >.blush::before,
            .blush::after {
                content'';
                position: absolute;
                top30%;
                width25px; 
                height5px;
                transformrotate(0deg); 
                backgroundrgb(250108127);
                border-radius100%;
                box-shadow0 0 5px 4px rgb(250108127);
            }
            >.blush::before {
                left20%;
            }
            >.blush::after {
                right20%;
            }
            >.mouth {
                position: absolute;
                top32%;
                width20px;
                height20px;
                background: 
                    linear-gradient(135degrgb(255207050%, 
                    rgb(224184250%);
                transformrotate(45deg);
                border-radius5% 15%;
            }
            > .feet::before,
            .feet::after{
                content'';
                position: absolute; 
                bottom: -12px;
                width10px;
                height15px;
                border7px solid rgb(714920);
            }
            > .feet::before{
                left60px;
                border-radius80% 100% 100% 50%;
                transformrotate(-10deg);
                border-color: transparent  transparent transparent rgb(714920);
            }
            > .feet::after{
                right60px;
                border-radius100% 80% 50% 0%;
                transformrotate(10deg);
                border-color: transparent rgb(714920) transparent transparent ;
            } 
        }
        >.crest {
            position: relative;
            top: -17%;
            width30px;
            height25px;
            backgroundrgb(2331919);
            border-radius50% 100% 20% 20%;
        }
        >.crest::before,
        .crest::after {
            content'';
            position: absolute;
            bottom0; 
            width20px; 
            backgroundrgb(2331919);
        }
        >.crest::before {
            left: -5px;
            height20px;
            border-radius100% 50% 0 20%;
        }
        >.crest::after {
            right: -15px;
            height15px;
            backgroundrgb(2331919);
            border-radius20% 200% 20% 30%;
        }
        > .hand{
            position: relative;
            top: -5%;
        }
        > .hand::before,
        .hand::after{
            content'';
            position: absolute;
        }
        > .hand::before{
            left:-135px;
            width20px;
            height80px;
            transformrotate(15deg);
            backgroundrgb(250242242);
            border-radius100% 0 50% 50%;
        }
        > .hand::after{
            right: -110px;
            width20px;
            height80px;
            transformrotate(-15deg);
            backgroundrgb(250,242,242);
            border-radius50% 100% 50% 50%;
        }
    }
}

看完上述内容,你们对使用css3怎么实现一个宠物小鸡有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

原文链接:https://www.jb51.net/css/639834.html

AI

开发者交流群×