纯css3实现宠物小鸡实例代码


Posted in HTML / CSS onOctober 08, 2018

最近看了很多关于css3的知识和文章,觉得css3用起来很方便,使用css3的话,在页面布局上可以省去很多不必要的代码。所以最近用css3仿写了我每天都照顾的宠物小鸡的模样,第一次写,有些细节处理的不够好。

先看最终效果图:

纯css3实现宠物小鸡实例代码

接下来是我书写的步骤:

首先是html,分别写出云朵,小鸡的身体,鸡冠,眼睛,嘴巴,腮红,翅膀,鸡爪

<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 {
        width: 100%;
        height: 800px;
        background: linear-gradient(rgb(170, 227, 253) 60%, rgb(149, 219, 126) 80px);
        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;
                bottom: 0;
            }
  .content::before {
                width: 40px;
                height: 40px;
                background: currentColor;
                left: -20px;
                border-radius: 100% 100% 0 100%;
            }
   .content::after {
                width: 35px;
                height: 30px;
                background: currentColor;
                right: -20px;
                border-radius: 100% 100% 100% 0;
            }

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

纯css3实现宠物小鸡实例代码

.content,
.content::before,
.content::after {
                box-shadow: 
                -200px 50px 0 -5px rgb(191, 232, 252),
                 200px 60px 0 10px rgb(191, 233, 253);
            }

纯css3实现宠物小鸡实例代码

云朵实现了。

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

.egg {
            width: 220px;
            height: 260px;
            border-radius: 100%;
            background: linear-gradient(rgb(254, 249, 249) 60%,rgb(221, 213, 213));
            position: absolute;
            display: flex;
            flex-direction: column;
            align-items: center;
            box-shadow: 0 -10px 10px 3px rgba(211, 194, 194,0.4) inset;
}

纯css3实现宠物小鸡实例代码

鸡冠和云朵的写法差不多

.crest {
            position: relative;
            top: -17%;
            width: 30px;
            height: 25px;
            background: rgb(233, 19, 19);
            border-radius: 50% 100% 20% 20%;
        }
  .crest::before,
  .crest::after {
            content: '';
            position: absolute;
            bottom: 0; 
            width: 20px; 
            background: rgb(233, 19, 19);
        }
  .crest::before {
            left: -5px;
            height: 20px;
            border-radius: 100% 50% 0 20%;
        }
  .crest::after {
            right: -15px;
            height: 15px;
            background: rgb(233, 19, 19);
            border-radius: 20% 200% 20% 30%;
        }

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

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

body {
    margin: 0;
    width: 100%;
    height: 100%;
    >.content {
        width: 100%;
        height: 800px;
        background: linear-gradient(rgb(170, 227, 253) 60%, rgb(149, 219, 126) 80px);
        display: flex;
        justify-content: center;
        align-items: center;
        >.cloud {
            position: absolute;
            top: 5%;
            color: rgb(216, 242, 254);
            >.content {
                width: 50px;
                height: 50px;
                background: currentColor;
                border-radius: 100% 100% 0 0;
            }
            >.content::before,
            >.content::after {
                content: '';
                position: absolute;
                bottom: 0;
            }
            >.content::before {
                width: 40px;
                height: 40px;
                background: currentColor;
                left: -20px;
                border-radius: 100% 100% 0 100%;
            }
            >.content::after {
                width: 35px;
                height: 30px;
                background: currentColor;
                right: -20px;
                border-radius: 100% 100% 100% 0;
            } 
            >.content,
            .content::before,
            .content::after {
                box-shadow: -200px 50px 0 -5px rgb(191, 232, 252),
                             200px 60px 0 10px rgb(191, 233, 253);
            }
        }
        >.egg {
            width: 220px;
            height: 260px;
            border-radius: 100%;
            background: linear-gradient(rgb(254, 249, 249) 60%,rgb(221, 213, 213));
            position: absolute;
            display: flex;
            flex-direction: column;
            align-items: center;
            box-shadow: 0 -10px 10px 3px rgba(211, 194, 194,0.4) inset;
            >.eye::before,
            .eye::after {
                content: '';
                position: absolute;
                top: 15%;
                width: 12px;
                height: 28px;
                border-radius: 100%;
                background: radial-gradient(white 1px, rgb(57, 56, 57) 5%);
            }
            > .eye::before{
                left: 28%;
            }
            >.eye::after {
                right: 28%;
            }
            >.blush::before,
            .blush::after {
                content: '';
                position: absolute;
                top: 30%;
                width: 25px; 
                height: 5px;
                transform: rotate(0deg); 
                background: rgb(250, 108, 127);
                border-radius: 100%;
                box-shadow: 0 0 5px 4px rgb(250, 108, 127);
            }
            >.blush::before {
                left: 20%;
            }
            >.blush::after {
                right: 20%;
            }
            >.mouth {
                position: absolute;
                top: 32%;
                width: 20px;
                height: 20px;
                background: 
                    linear-gradient(135deg, rgb(255, 207, 0) 50%, 
                    rgb(224, 184, 2) 50%);
                transform: rotate(45deg);
                border-radius: 5% 15%;
            }
            > .feet::before,
            .feet::after{
                content: '';
                position: absolute; 
                bottom: -12px;
                width: 10px;
                height: 15px;
                border: 7px solid rgb(71, 49, 20);
            }
            > .feet::before{
                left: 60px;
                border-radius: 80% 100% 100% 50%;
                transform: rotate(-10deg);
                border-color: transparent  transparent transparent rgb(71, 49, 20);
            }
            > .feet::after{
                right: 60px;
                border-radius: 100% 80% 50% 0%;
                transform: rotate(10deg);
                border-color: transparent rgb(71, 49, 20) transparent transparent ;
            } 
        }
        >.crest {
            position: relative;
            top: -17%;
            width: 30px;
            height: 25px;
            background: rgb(233, 19, 19);
            border-radius: 50% 100% 20% 20%;
        }
        >.crest::before,
        .crest::after {
            content: '';
            position: absolute;
            bottom: 0; 
            width: 20px; 
            background: rgb(233, 19, 19);
        }
        >.crest::before {
            left: -5px;
            height: 20px;
            border-radius: 100% 50% 0 20%;
        }
        >.crest::after {
            right: -15px;
            height: 15px;
            background: rgb(233, 19, 19);
            border-radius: 20% 200% 20% 30%;
        }
        > .hand{
            position: relative;
            top: -5%;
        }
        > .hand::before,
        .hand::after{
            content: '';
            position: absolute;
        }
        > .hand::before{
            left:-135px;
            width: 20px;
            height: 80px;
            transform: rotate(15deg);
            background: rgb(250, 242, 242);
            border-radius: 100% 0 50% 50%;
        }
        > .hand::after{
            right: -110px;
            width: 20px;
            height: 80px;
            transform: rotate(-15deg);
            background: rgb(250,242,242);
            border-radius: 50% 100% 50% 50%;
        }
    }
}

总结

以上所述是小编给大家介绍的纯css3实现宠物小鸡实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对三水点靠木网站的支持!

HTML / CSS 相关文章推荐
纯CSS实现的大小渐变、渐远效果
Apr 15 HTML / CSS
一款纯css3实现的鼠标经过按钮特效教程
Nov 09 HTML / CSS
利用CSS3实现文字折纸效果实例代码
Jul 10 HTML / CSS
CSS3 按钮边框动画的实现
Nov 12 HTML / CSS
canvas学习笔记之绘制简单路径
Jan 28 HTML / CSS
html5 css3实例教程 一款html5和css3实现的小机器人走路动画
Oct 20 HTML / CSS
浅谈HTML5 &amp; CSS3的新交互特性
Jul 19 HTML / CSS
解决HTML5中滚动到底部的事件问题
Aug 22 HTML / CSS
Html5获取高德地图定位天气的方法
Dec 26 HTML / CSS
AmazeUI 加载进度条的实现示例
Aug 20 HTML / CSS
Html5页面点击遮罩层背景关闭遮罩层
Nov 30 HTML / CSS
HTML中link标签属性的具体用法
May 07 HTML / CSS
使用纯 CSS 创作一个脉动 loader效果的源码
Sep 28 #HTML / CSS
利用CSS3动画实现圆圈由小变大向外扩散的效果实例
Sep 10 #HTML / CSS
详解CSS3原生支持div铺满浏览器的方法
Aug 30 #HTML / CSS
利用CSS3实现文字折纸效果实例代码
Jul 10 #HTML / CSS
CSS3实现文本垂直排列的方法
Jul 10 #HTML / CSS
CSS3实现背景透明文字不透明的示例代码
Jun 25 #HTML / CSS
css3 column实现卡片瀑布流布局的示例代码
Jun 22 #HTML / CSS
You might like
php array_map使用自定义的函数处理数组中的每个值
2016/10/26 PHP
PHP内置加密函数详解
2016/11/20 PHP
PHP学习笔记之session
2018/05/06 PHP
JS中的public和private对象,即static修饰符
2012/01/18 Javascript
基于jQuery实现的文字按钮表单特效整理
2014/12/07 Javascript
Javascript中的五种数据类型详解
2014/12/26 Javascript
JS建造者模式基本用法实例分析
2015/06/30 Javascript
jquery小火箭返回顶部代码分享
2015/08/19 Javascript
jQuery-1.9.1源码分析系列(十)事件系统之事件包装
2015/11/20 Javascript
Backbone.js框架中简单的View视图编写学习笔记
2016/02/14 Javascript
javascript时间戳和日期字符串相互转换代码(超简单)
2016/06/22 Javascript
BootStrap使用popover插件实现鼠标经过显示并保持显示框
2016/06/23 Javascript
Node.js使用NodeMailer发送邮件实例代码
2017/03/06 Javascript
Vue中的混入的使用(vue mixins)
2018/06/01 Javascript
详解axios中封装使用、拦截特定请求、判断所有请求加载完毕)
2019/04/09 Javascript
angular4应用中输入的最小值和最大值的方法
2019/05/17 Javascript
JavaScrip数组去重操作实例小结
2019/06/20 Javascript
Python运算符重载用法实例
2015/05/28 Python
Django的信号机制详解
2017/05/05 Python
Python基于回溯法子集树模板实现图的遍历功能示例
2017/09/05 Python
浅谈python print(xx, flush = True) 全网最清晰的解释
2020/02/21 Python
定义css设备类型-Media Queries图表简介及使用方法
2013/01/21 HTML / CSS
越南电子产品购物网站:FPT Shop
2017/12/02 全球购物
澳洲的服装老品牌:SABA
2018/02/06 全球购物
国际金融专业大学生职业生涯规划书
2013/12/28 职场文书
敬老模范事迹
2014/05/21 职场文书
环境保护与污染治理求职信
2014/07/16 职场文书
学校运动会广播稿100条
2014/09/14 职场文书
2015关爱留守儿童工作总结
2014/12/12 职场文书
慈善献爱心倡议书
2015/04/27 职场文书
2015年工会工作总结范文
2015/07/23 职场文书
生产车间管理制度
2015/08/04 职场文书
深入理解python多线程编程
2021/04/18 Python
简单谈谈Python面向对象的相关知识
2021/06/28 Python
Python pandas之求和运算和非空值个数统计
2021/08/07 Python
Windows 11上手初体验:任务栏和开始菜单等迎来大改
2021/11/21 数码科技