纯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 相关文章推荐
css3动画事件—webkitAnimationEnd与计时器time事件
Jan 31 HTML / CSS
css3+jq创作含苞待放的荷花
Feb 20 HTML / CSS
CSS3 transform的skew属性值图文详解
Jul 21 HTML / CSS
浅析与CSS3的loading动画加载相关的transition优化
May 18 HTML / CSS
浅谈CSS3中display属性的Flex布局的方法
Aug 14 HTML / CSS
基于HTML5的WebSocket的实例代码
Aug 15 HTML / CSS
html5中svg canvas和图片之间相互转化思路代码
Jan 24 HTML / CSS
HTML5注册页面示例代码
Mar 27 HTML / CSS
HTML5的download属性详细介绍和使用实例
Apr 23 HTML / CSS
Html5 web本地存储实例详解
Jul 28 HTML / CSS
CSS实现背景图片全屏铺满自适应的3种方式
Jul 07 HTML / CSS
使用 CSS 构建强大且酷炫的粒子动画效果
Aug 14 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初学者头疼问题总结
2006/07/08 PHP
php读取二进制流(C语言结构体struct数据文件)的深入解析
2013/06/13 PHP
修改destoon会员公司的伪静态中的com目录的方法
2014/08/21 PHP
初识laravel5
2015/03/02 PHP
laravel框架中间件 except 和 only 的用法示例
2019/07/12 PHP
JS 显示当前日期与时间的代码
2010/03/24 Javascript
获取div编辑框,textarea,input text的光标位置 兼容IE,FF和Chrome的方法介绍
2012/11/08 Javascript
jquery 缓存问题的几个解决方法
2013/11/11 Javascript
JS实现的4种数字千位符格式化方法分享
2015/03/02 Javascript
jQuery实现的tab标签切换效果示例
2016/09/05 Javascript
基于AngularJS实现iOS8自带的计算器
2016/09/12 Javascript
Bootstrap CDN和本地化环境搭建
2016/10/26 Javascript
Vue.js组件tree实现无限级树形菜单
2016/12/02 Javascript
详解webpack2+React 实例demo
2017/09/11 Javascript
使用JS模拟锚点跳转的实例
2018/02/01 Javascript
vue 组件高级用法实例详解
2018/04/11 Javascript
微信小程序实现的一键复制功能示例
2019/04/24 Javascript
[01:26]神话结束了,却也刚刚开始——DOTA2新英雄玛尔斯驾临战场
2019/03/10 DOTA
跟老齐学Python之正规地说一句话
2014/09/28 Python
Python Tkinter GUI编程入门介绍
2015/03/10 Python
使用Python的Tornado框架实现一个一对一聊天的程序
2015/04/25 Python
详解Python网络框架Django和Scrapy安装指南
2019/04/01 Python
python主线程与子线程的结束顺序实例解析
2019/12/17 Python
将labelme格式数据转化为标准的coco数据集格式方式
2020/02/17 Python
python GUI库图形界面开发之PyQt5信号与槽事件处理机制详细介绍与实例解析
2020/03/08 Python
python利用platform模块获取系统信息
2020/10/09 Python
python 使用openpyxl读取excel数据
2021/02/18 Python
The Beach People美国:澳洲海滨奢华品牌
2018/07/05 全球购物
应届毕业生的个人自我鉴定
2013/10/24 职场文书
人力资源专业推荐信
2013/11/29 职场文书
十八大报告观后感
2014/01/28 职场文书
大学毕业自我评价
2014/02/02 职场文书
商务英语专业毕业生求职信
2014/07/06 职场文书
2015年志愿者服务工作总结
2015/04/20 职场文书
2016中秋节晚会开场白
2015/11/26 职场文书
Go语言中break label与goto label的区别
2021/04/28 Golang