热门标签 | HotTags
当前位置:  开发笔记 > 前端 > 正文

【二次元的CSS】--用DIV+LESS做一个小黄人构造器

【二次元的CSS】--用DIV+LESS做一个小黄人构造器

用 DIV + CSS3 画小黄人

仅仅使用p作为身体的布局,用css3的各种transform和圆角属性来绘制各个细节的形状,当然也不会使用任何图片哦。那就没意思了。有的同学说,用canvas不是能画得更逼真而且更简单吗?这点我也非常赞同,但我的理由还是,那就没意思了。

这次用到了一些LESS的特性,通过设置一些指定的参数来生成不同种类、不同身材的小黄人。

GitHub传送门: https://github.com/lancer07/css3Minons

效果是这个样子的

首先 先做个标准版的(ps:也就是图中的第一个小黄人)

HTML结构如下:(ps:每个小黄人的html结构都是一样的)

LESS代码如下:(ps:先定义一个小黄人的类,然后通过设置参数来实例化每个小黄人)

定义 小黄人 类

.Minion(@width:1;@height:1;@eye:2){    width: 380px * @width;    height:700px * @height;    position:absolute;    margin-top: -100px;    margin-left:-20px;    transform : scale(0.5,0.5);    .hairs{        position:absolute;        top: -40px;        z-index: 3;        width: 100%;        .hair{            background:#000;            width:2px;            height:70px;            position:absolute        }        .hair1{            .hair;            left:45%;            transform:rotate(-20deg);        }        .hair2{            .hair;            left:50%;        }        .hair3{            .hair;            left:55%;            transform:rotate(20deg);        }    }    .body{        overflow: hidden;        background: #fff500;        width: 380px * @width;        position:absolute;        z-index: 1;        height:700px * @height;        border-radius: 180px * @width;    }    .glasses-type{ //眼镜        height:52px;        background:#1f1a17;        width:100%;        position: absolute;        top: 200px;        z-index: 1;    }        .glasses{        z-index: 2;        position:absolute;        background:#dededd;        border:2px solid #1f1a17;        width:150px;        height:150px;        border-radius: 50%;        top: 140px;        &.left-glasses when (@eye = 2){            left:8%;            .ball{                //left : 45%;                animation: eye 1.5s infinite ease;            }        }        &.right-glasses when (@eye = 2){            right:8%;            .ball{                //right:45%;                animation: eye 1.5s infinite ease;            }        }        &.left-glasses when (@eye = 1){            left:50%;            margin-left: -90px;            width: 180px;            height: 180px;            .eye{                width: 150px;                height: 150px;                .ball{                    animation: eye 1.5s infinite ease;                }            }        }        &.right-glasses when (@eye = 1){            display: none;        }        .eye{            background:#fff;            width:120px;            height:120px;            border-radius: 50%;            border:2px solid #1f1a17;            margin:15px auto;            position:relative;            .ball{                background:#8f5444;                width:40px;                height:40px;                border-radius: 50%;                border:2px solid #1f1a17;                position:absolute;                top: 40%;                transition: all .15s linear;                strong{                    display: block;                    width:20px;                    height:20px;                    background:#1f1a17;                    border-radius: 50%;                    position:absolute;                    top: 10px;                    left:10px;                }            }        }    }    .mouth{        width:40%;        height:80px;        background:#fff;        position:absolute;        bottom:42%;        left:30%;        z-index: 1;        border-radius: 120px 120px 40px 40px;        border:2px solid #1f1a17;        overflow:hidden;        animation: up-down 0.5s infinite ease;        .tooths{            .tooth{                border-right:2px solid #1f1a17;                height:100%;                width:0;                position:absolute;            }            .tooth1{                .tooth;                left:25%;            }            .tooth2{                .tooth;                left:50%;            }            .tooth3{                .tooth;                left:75%;            }            .line{                width:100%;                top: 48%;                border-top:3px solid #1f1a17;                position:absolute;            }        }    }    .arm{        position:absolute;        width:50px;        height:400px;        background:#fff500;        border-radius: 50px;        top: 190px;        z-index: 0;        &.left-arm{            left:-20px;            transform:rotate(20deg);        }        &.right-arm{            right:-20px;            transform:rotate(-20deg);        }        .hand{            position:absolute;            bottom:0;            width:60px;            height:60px;            border-radius: 50%;            background:#1f1a17;            left:-5px;        }    }    .cloth{        background:#667ab3;        border-radius: 20px;        bottom:20px;        width:80%;        height:250px;        position:absolute;        z-index: 1;        left:10%;    }    .pocket{        border:2px solid #1f1a17;        border-radius: 5px 5px 30px 30px;        width:100px;        left:50%;        margin-left: -50px;        height:100px;        position:absolute;        z-index: 2;        bottom: 80px;        >p{            background:#1f1a17;            width:50px;            height:50px;            border-radius: 50%;            top: 20px;            left:25px;            position:absolute;            >p{                width:20px;                height:20px;                border:5px solid #667ab3;                transform:rotate(45deg);                position:absolute;                top: 10px;                left:10px            }        }    }    .trousers{        background:#667ab3;        border-radius: 10px 10px 130px 130px;        bottom:0;        width:100%;        height:160px;        position:absolute;        z-index: 1;    }    .straps{        width:40px;        height:150px;        position:absolute;        z-index: 1;        background:#667ab3;        bottom:230px;        &.left-straps{            left:10px;            transform:rotate(-40deg);        }        &.right-straps{            right:10px;            transform:rotate(40deg);        }        .fastener{            background:#1f1a17;            width:20px;            height:20px;            border-radius: 50%;            bottom:10px;            position:absolute;            left:10px;        }    }    .leg{        background:#667ab3;        width:70px;        height:120px;        position:absolute;        bottom:-80px;        &.left-leg{            left:20%;            .footer{                right:-2px;                border-radius: 100px 0 0 20px;            }        }        &.right-leg{            right:20%;            .footer{                left:-2px;                border-radius: 0 100px 20px 0;            }        }        .footer{            background:#1f1a17;            width:100px;            height:50px;            position:absolute;            bottom:0;        }    }}

实例化

.minion-1{    z-index: 1;    top: 50px;    left: 0;    .Minion(1,1,2);    }.minion-2{    z-index: 2;    top: 0;    left: 24%;    .Minion(0.88,1.1,1);    }.minion-3{    z-index: 2;    top: 44px;    left: 42%;    .Minion(1.15,1.02,1);    }.minion-4{    z-index: 1;    top: 5px;    left: 67%;    .Minion(1,1.1,2);    }

最后加点料

附加了2个小动画效果,眼睛转动和牙齿抖动。

@keyframes eye {    0% {          transform:rotate(0,0);    }    50% {          transform:translate(70px,0px)    }    100% {          transform:translate(0px,0px)    }}@keyframes up-down {    0% {          transform:rotate(0,0);    }    50% {          transform:translate(0,2px)    }    100% {          transform:translate(0,0)    }}

后续

没有特别详细的描述每个细节部分,大家看一下源码或者fork一下就能知道具体每个元素是怎么实现的了。当然这个肯定是有bug的,比如参数设置的过大或者过小,都会导致生成出来的小黄人乱七八糟,也欢迎大家吐槽。

推荐阅读
  • Vue 2 中解决页面刷新和按钮跳转导致导航栏样式失效的问题
    本文介绍了如何通过配置路由的 meta 字段,确保 Vue 2 项目中的导航栏在页面刷新或内部按钮跳转时,始终保持正确的 active 样式。具体实现方法包括设置路由的 meta 属性,并在 HTML 模板中动态绑定类名。 ... [详细]
  • QUIC协议:快速UDP互联网连接
    QUIC(Quick UDP Internet Connections)是谷歌开发的一种旨在提高网络性能和安全性的传输层协议。它基于UDP,并结合了TLS级别的安全性,提供了更高效、更可靠的互联网通信方式。 ... [详细]
  • 技术分享:从动态网站提取站点密钥的解决方案
    本文探讨了如何从动态网站中提取站点密钥,特别是针对验证码(reCAPTCHA)的处理方法。通过结合Selenium和requests库,提供了详细的代码示例和优化建议。 ... [详细]
  • 深入理解Cookie与Session会话管理
    本文详细介绍了如何通过HTTP响应和请求处理浏览器的Cookie信息,以及如何创建、设置和管理Cookie。同时探讨了会话跟踪技术中的Session机制,解释其原理及应用场景。 ... [详细]
  • 本文详细介绍了如何使用Python编写爬虫程序,从豆瓣电影Top250页面抓取电影信息。文章涵盖了从基础的网页请求到处理反爬虫机制,再到多页数据抓取的全过程,并提供了完整的代码示例。 ... [详细]
  • 在Linux系统中配置并启动ActiveMQ
    本文详细介绍了如何在Linux环境中安装和配置ActiveMQ,包括端口开放及防火墙设置。通过本文,您可以掌握完整的ActiveMQ部署流程,确保其在网络环境中正常运行。 ... [详细]
  • 如何在WPS Office for Mac中调整Word文档的文字排列方向
    本文将详细介绍如何使用最新版WPS Office for Mac调整Word文档中的文字排列方向。通过这些步骤,用户可以轻松更改文本的水平或垂直排列方式,以满足不同的排版需求。 ... [详细]
  • 扫描线三巨头 hdu1928hdu 1255  hdu 1542 [POJ 1151]
    学习链接:http:blog.csdn.netlwt36articledetails48908031学习扫描线主要学习的是一种扫描的思想,后期可以求解很 ... [详细]
  • This document outlines the recommended naming conventions for HTML attributes in Fast Components, focusing on readability and consistency with existing standards. ... [详细]
  • 深入理解OAuth认证机制
    本文介绍了OAuth认证协议的核心概念及其工作原理。OAuth是一种开放标准,旨在为第三方应用提供安全的用户资源访问授权,同时确保用户的账户信息(如用户名和密码)不会暴露给第三方。 ... [详细]
  • 2023 ARM嵌入式系统全国技术巡讲旨在分享ARM公司在半导体知识产权(IP)领域的最新进展。作为全球领先的IP提供商,ARM在嵌入式处理器市场占据主导地位,其产品广泛应用于90%以上的嵌入式设备中。此次巡讲将邀请来自ARM、飞思卡尔以及华清远见教育集团的行业专家,共同探讨当前嵌入式系统的前沿技术和应用。 ... [详细]
  • 本周信息安全小组主要进行了CTF竞赛相关技能的学习,包括HTML和CSS的基础知识、逆向工程的初步探索以及整数溢出漏洞的学习。此外,还掌握了Linux命令行操作及互联网工作原理的基本概念。 ... [详细]
  • 构建基于BERT的中文NL2SQL模型:一个简明的基准
    本文探讨了将自然语言转换为SQL语句(NL2SQL)的任务,这是人工智能领域中一项非常实用的研究方向。文章介绍了笔者在公司举办的首届中文NL2SQL挑战赛中的实践,该比赛提供了金融和通用领域的表格数据,并标注了对应的自然语言与SQL语句对,旨在训练准确的NL2SQL模型。 ... [详细]
  • 在现代网络环境中,两台计算机之间的文件传输需求日益增长。传统的FTP和SSH方式虽然有效,但其配置复杂、步骤繁琐,难以满足快速且安全的传输需求。本文将介绍一种基于Go语言开发的新一代文件传输工具——Croc,它不仅简化了操作流程,还提供了强大的加密和跨平台支持。 ... [详细]
  • 解决微信电脑版无法刷朋友圈问题:使用安卓远程投屏方案
    在工作期间想要浏览微信和朋友圈却不太方便?虽然微信电脑版目前不支持直接刷朋友圈,但通过远程投屏技术,可以轻松实现在电脑上操作安卓设备的功能。 ... [详细]
author-avatar
手机用户2602907455
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有