用HTML和CSS绘制佩奇:我不是佩奇

news2025/5/17 11:47:32

在这篇博客中,我将解析一个完全使用HTML和CSS绘制的佩奇(Pig)形象。这个项目展示了CSS的强大能力,仅用样式就能创造出复杂的图形,而不需要任何图片或JavaScript。

项目概述

这个名为"我不是佩奇"的项目是一个纯CSS绘制的卡通猪形象。整个图形由多个<div>元素组成,每个元素都通过精确的CSS定位和样式来构建猪的各个部分。

效果图展示:

结构分解

头部结构

  • 主头部(.pig_head)
  • 耳朵(.ear_left.ear_right)
  • 鼻子和鼻孔
  • 眼睛(包括眼白、眼球和边框)
  • 嘴巴(上中下三部分)
  • 脸颊

身体结构

  • 主体(.pig_body_bottom)
  • 手部(左右各三部分)
  • 脚部和鞋子
  • 尾巴(多个部分组合)

装饰元素

  • 阴影(.pig_shadow)

整体源码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>我不是佩奇</title>
    <style type="text/css">

    div {
        position: absolute;
        transform-origin: left top;
    }
.pig_container {
    width: 800px;
    height: 800px;
    top: 0;
    left: 50px;
}

.pig_head {
    width: 300px;
    height: 200px;
    top: 100px;
    left: 100px;
    border-radius: 95% 50% 50% 50%/ 87% 80% 68% 50%;
    border: 6px solid #ef96c2;
    background-color: #ffb3da;
    transform: rotate(30deg);
    z-index: 100;
    box-sizing: border-box;
}
.pig_head_white_left_bottom {
    width: 200px;
    height: 154px;
    bottom: -7px;
    left: -38px;
    background-color: #fff;
    box-sizing: border-box;
}
.pig_head_white_left_top {


    width: 200px;
    height: 66px;
    bottom: 84px;
    background-color: #ffb3da;
    box-sizing: border-box;
    top: 166px;
    left: 134px;
    transform: rotate(34deg);
    z-index: 103;
}
.left_eye, .right_eye, .face, .mouth {
    z-index: 104;
}
.pig_nose {
    width: 51px;
    height: 70px;
    top: 147px;
    left: 107px;
    border-radius: 72% 72% 72% 72%/ 72% 72% 72% 72%;
    border: 6px solid #ef96c2;
    background-color: #ffb3da;
    transform: rotate(36deg);
    z-index: 103;
    box-sizing: border-box;
}
.pig_nose_bottom {
    width: 88px;
    height: 13px;
    top: 209px;
    left: 84px;
    border-radius: 50% 50% 50% 50%/ 0% 0% 100% 100%;
    border: 6px solid #ef96c2;
    background-color: #ffb3da;
    transform: rotate(35deg);
    z-index: 102;
    box-sizing: border-box;
    border-top-color: #ffb3da;
}
.pig_jaw {
    width: 97px;
    height: 104px;
    top: 249px;
    left: 141px;
    border-radius: 0% 0% 0% 76%/ 0% 0% 0% 74%;
    border: 6px solid #ef96c2;
    background-color: #ffb3da;
    transform: rotate(22deg);
    z-index: 100;
    box-sizing: border-box;
    border-top-color: #ffb3da;
    border-right-color: #ffb3da;
}
.pig_jaw_right {
    width: 13px;
    height: 6px;
    background-color: #ef96c2;
    top: 373px;
    left: 186px;
    transform: rotate(19deg);
    z-index: 100;
}
.left_eye_bg {
    width: 29px;
    height: 29px;
    top: 177px;
    left: 170px;
    border-radius: 50% 50% 50% 50%/ 50% 50% 50% 50%;
    border: 6px solid #fff;
    background-color: #fff;
    z-index: 101;
    box-sizing: border-box;
}
.left_eye_ball {
    width: 10px;
    height: 10px;
    top: 181px;
    left: 171px;
    border-radius: 50% 50% 50% 50%/ 50% 50% 50% 50%;
    border: 6px solid #000;
    background-color: #000;
    z-index: 101;
    box-sizing: border-box;
}
.left_eye_border {
    width: 34px;
    height: 34px;
    top: 174px;
    left: 166px;
    border-radius: 50% 50% 50% 50%/ 50% 50% 50% 50%;
    border: 6px solid #ef96c2;
    background-color: transparent;
    z-index: 101;
    box-sizing: border-box;
}

.right_eye_bg {
    width: 28px;
    height: 28px;
    top: 194px;
    left: 205px;
    border-radius: 50% 50% 50% 50%/ 50% 50% 50% 50%;
    border: 6px solid #fff;
    background-color: #fff;
    z-index: 101;
    box-sizing: border-box;
}
.right_eye_ball {
    width: 10px;
    height: 10px;
    top: 199px;
    left: 208px;
    border-radius: 50% 50% 50% 50%/ 50% 50% 50% 50%;
    border: 6px solid #000;
    background-color: #000;
    z-index: 101;
    box-sizing: border-box;
}
.right_eye_border {
    width: 35px;
    height: 37px;
    top: 191px;
    left: 202px;
    border-radius: 50% 50% 50% 50%/ 50% 50% 50% 50%;
    border: 6px solid #ef96c2;
    background-color: transparent;
    z-index: 101;
    box-sizing: border-box;
}

.mouth_bottom {
    width: 97px;
    height: 45px;
    top: 273px;
    left: 154px;
    border-radius: 50% 50% 50% 50%/ 0% 0% 100% 100%;
    border: 6px solid #d44b81;
    background-color: #000;
    z-index: 101;
    box-sizing: border-box;
    transform: rotate(19deg);
}
.mouth_middle {
    width: 98px;
    height: 27px;
    top: 272px;
    left: 154px;
    border-radius: 0% 0% 50% 50%/ 0% 0% 100% 100%;
    border: 6px solid #d44b81;
    background-color: #ffb3da;
    z-index: 101;
    box-sizing: border-box;
    transform: rotate(19deg);
    border-top-color: #ffb3da;
}
.mouth_top {
        width: 135px;
    height: 66px;
    top: 231px;
    left: 149px;
    border-radius: 50% 50% 50% 50%/ 0% 0% 100% 100%;
    background-color: #ffb3da;
    z-index: 101;
    transform: rotate(13deg);


}
.face {
    width: 49px;
    height: 59px;
    top: 243px;
    left: 269px;
    border-radius: 50% 50% 50% 50%/ 50% 50% 50% 50%;
    background-color: #ff96ce;
    transform: rotate(26deg);
}

.nose_kong_left {
    width: 12px;
    height: 12px;
    top: 179px;
    left: 93px;
    border-radius: 50% 50% 50% 50%/ 50% 50% 50% 50%;
    background-color: #da6c9b;
    z-index: 104;
}
.nose_kong_right {
    width: 12px;
    height: 12px;
    top: 182px;
    left: 109px;
    border-radius: 50% 50% 50% 50%/ 50% 50% 50% 50%;
    background-color: #da6c9b;
    z-index: 104;
}

.ear_left {
    width: 24px;
    height: 52px;
    top: 126px;
    left: 226px;
    border: 6px solid #ef96c2;
    border-radius: 50% 50% 50% 50%/ 35% 40% 50% 50%;
    background-color: #ffb3da;
    z-index: 99;
    transform: rotate(18deg);
}
.ear_right {
    width: 24px;
    height: 52px;
    top: 150px;
    left: 280px;
    border: 6px solid #ef96c2;
    border-radius: 50% 50% 50% 50%/ 35% 40% 50% 50%;
    background-color: #ffb3da;
    z-index: 99;
    transform: rotate(36deg);
}

.pig_body_bottom {
    width: 215px;
    height: 197px;
    top: 305px;
    left: 108px;
    border: 6px solid #e33b32;
    border-radius: 50% 50% 50% 50%/ 100% 100% 0% 0%;
    background-color: #eb5b50;
    z-index: 99;
}

.hand_left_middle {
    width: 78px;
    height: 12px;
    top: 432px;
    left: 63px;
    border-radius: 100% 100% 100% 17%/ 100% 90% 16% 90%;
    background-color: #ffbadf;
    z-index: 99;
    transform: rotate(-35deg);
}
.hand_left_top {
    width: 28px;
    height: 9px;
    top: 415px;
    left: 63px;
    border-radius: 100% 100% 100% 35%/ 100% 90% 16% 90%;
    background-color: #ffbadf;
    z-index: 99;
}
.hand_left_bottom {
        width: 20px;
    height: 9px;
    top: 420px;
    left: 93px;
    border-radius: 60% 59% 65% 90%/ 100% 90% 89% 90%;
    background-color: #ffbadf;
    z-index: 99;
    transform: rotate(98deg);
}

.hand_right_middle {
        width: 79px;
    height: 11px;
    top: 374px;
    left: 309px;
    border-radius: 100% 100% 15% 17%/ 99% 92% 90% 90%;
    background-color: #ffbadf;
    z-index: 99;
    transform: rotate(28deg);
}
.hand_right_top {
    width: 28px;
    height: 10px;
    top: 397px;
    left: 350px;
    border-radius: 100% 100% 15% 17%/ 99% 92% 90% 90%;
    background-color: #ffbadf;
    z-index: 99;
    transform: rotate(-7deg);
}
.hand_right_bottom {
    width: 28px;
    height: 11px;
    top: 395px;
    left: 356px;
    border-radius: 100% 100% 62% 17%/ 99% 92% 90% 90%;
    background-color: #ffbadf;
    z-index: 99;
    transform: rotate(69deg);
}
.left_foot {
        width: 11px;
    height: 52px;
    top: 507px;
    left: 175px;
    border-radius: 100% 100% 100% 100%/ 50% 50% 21% 20%;
    background-color: #ffbadf;
    z-index: 99;
}
.left_shoes {
        width: 51px;
    height: 14px;
    top: 553px;
    left: 138px;
    border-radius: 58% 187% 180% 50%/ 130% 123% 113% 100%;
    background-color: #000;
    z-index: 99;
    transform: rotate(0deg);
}
.right_foot {
    left: 268px;
}
.right_shoes {
    left: 230px;
}
.pig_shadow {
    width: 240px;
    height: 47px;
    top: 535px;
    left: 101px;
    border-radius: 50% 50% 50% 50%/ 50% 50% 50% 50%;
    background-color: rgba(171, 171, 171, 0.7);
    transform: rotate(-1deg);
}
.tail_left {
    width: 19px;
    height: 8px;
    top: 472px;
    left: 330px;
    border-radius: 50% 50% 50% 50%/ 0% 0% 100% 100%;
    transform: rotate(-9deg);
    background-color: #ffbadf;
    z-index: 99;
}
.tail_left_blank {
    width: 30px;
    height: 15px;
    top: 466px;
    left: 332px;
    border-radius: 50% 50% 50% 50%/ 0% 0% 100% 100%;
    transform: rotate(-36deg);
    background-color: #fff;
    z-index: 99;
}
.tail_right {
    width: 21px;
    height: 5px;
    top: 451px;
    left: 343px;
    border-radius: 0% 0% 51% 50%/ 0% 0% 100% 100%;
    transform: rotate(31deg);
    background-color: #fff;
    z-index: 99;
    border: 8px solid #ffbadf;
    border-top-color: #fff;
}
.tail_blank {
    width: 36px;
    height: 21px;
    top: 437px;
    left: 351px;
    transform: rotate(34deg);
    background-color: #fff;
    z-index: 99;
}
.tail_middle {
    width: 7px;
    height: 11px;
    top: 450px;
    left: 336px;
    border: 8px solid #ffbadf;
    border-radius: 50% 50% 50% 50%/ 50% 50% 50% 50%;
    background-color: #fff;
    z-index: 99;
}
.tail_circle {
    width: 17px;
    height: 8px;
    top: 475px;
    left: 358px;
    border-radius: 36% 37% 62% 63%/ 99% 92% 90% 90%;
    background-color: #ffbadf;
    z-index: 99;
    transform: rotate(-40deg);
}

    </style>
</head>
<body>
<h1 align="center">我不是佩奇</h1>
<div class="pig_container">
    <!-- 尾巴 -->
    <div class="tail_left"></div>
    <div class="tail_right"></div>
    <div class="tail_blank"></div>
    <div class="tail_middle"></div>
    <div class="tail_circle"></div>
    <!-- 底部阴影 -->
    <div class="pig_shadow"></div>
    <!-- 左脚 -->
    <div class="left_foot"></div>
    <div class="left_foot right_foot"></div>
    <!-- 左鞋 -->
    <div class="left_shoes"></div>
    <div class="left_shoes right_shoes"></div>
    <!-- 左手 -->
    <div>
        <div class="hand_left_top"></div>
        <div class="hand_left_bottom"></div>
        <div class="hand_left_middle"></div>
    </div>
    <!-- 身体 -->
    <div class="pig_body_bottom"></div>
    <!-- 右手 -->
    <div>
        <div class="hand_right_top"></div>
        <div class="hand_right_bottom"></div>
        <div class="hand_right_middle"></div>
    </div>

    <!-- 猪头 -->
    <div>
        <!-- 耳朵 -->
        <div class="ear_left"></div>
        <div class="ear_right"></div>
        <div class="pig_head">
            <div class="pig_head_white_left_bottom"></div>
        </div>
            <div class="pig_head_white_left_top"></div>
        <!-- 鼻子 -->
        <div class="pig_nose"></div>
        <!-- 下巴 -->
        <div class="pig_jaw"></div>
        <div class="pig_jaw_right"></div>
        <div class="pig_nose_bottom"></div>
        <!-- 鼻孔 -->
        <div class="nose_kong_left"></div>
        <div class="nose_kong_right"></div>
        <!-- 左眼 -->
        <div class="left_eye">
            <div class="left_eye_bg"></div>
            <div class="left_eye_ball"></div>
            <div class="left_eye_border"></div>
        </div>
        <!-- 右眼 -->
        <div class="right_eye">
            <div class="right_eye_bg"></div>
            <div class="right_eye_ball"></div>
            <div class="right_eye_border"></div>
        </div>
        <!-- 嘴巴 -->
        <div class="mouth">
            <div class="mouth_bottom"></div>
            <div class="mouth_middle"></div>
            <div class="mouth_top"></div>
        </div>
        <!-- 脸颊 -->
        <div class="face"></div>
    </div>
</div>
</body>
</html>

总结

这个项目展示了CSS在图形创作中的强大能力。通过精心计算的位置、变形和层次控制,仅用CSS就创造出了一个生动的卡通形象。这种技术可以应用于:

  • 图标设计
  • 简单的游戏角色
  • 品牌形象展示
  • 网页装饰元素

虽然这种实现方式在性能上可能不如SVG高效,但它是一个很好的CSS练习,展示了CSS的可能性边界。

你可以通过调整各种CSS参数来修改猪的外观,创造属于自己的独特版本,快来试试吧!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2333108.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

彩讯携Rich AICloud与一体机智算解决方案亮相中国移动云智算大会

2025年4月10日&#xff0c;2025中国移动云智算大会在苏州盛大开幕&#xff0c;本次大会以“由云向智 共绘算网新生态”为主题&#xff0c;与会嘉宾围绕算力展开重点探讨。 大会现场特设区域展出各参会单位的最新算力成果&#xff0c;作为中国移动重要合作伙伴&#xff0c;彩讯…

声学测温度原理解释

已知声速&#xff0c;就可以得到温度。 不同温度下的胜诉不同。 25度的声速大约346m/s 绝对温度-273度 不同温度下的声速。 FPGA 通过测距雷达测温度&#xff0c;固定测量距离&#xff0c;或者可以测出当前距离。已知距离&#xff0c;然后雷达发出声波到接收到回波的时间&a…

Cuto壁纸 2.6.9 | 解锁所有高清精选壁纸,无广告干扰

Cuto壁纸 App 提供丰富多样的壁纸选择&#xff0c;涵盖动物、风景、创意及游戏动漫等类型。支持分类查找与下载&#xff0c;用户可轻松将心仪壁纸设为手机背景&#xff0c;并享受软件内置的编辑功能调整尺寸。每天更新&#xff0c;确保用户总能找到新鲜、满意的壁纸。 大小&am…

C语言 AI 通义灵码 VSCode插件安装与功能详解

在 C 语言开发领域&#xff0c;一款高效的编码助手能够显著提升开发效率和代码质量。 通义灵码&#xff0c;作为阿里云技术团队打造的智能编码助手&#xff0c;凭借其强大的功能&#xff0c;正逐渐成为 C 语言开发者的新宠。 本文将深入探讨通义灵码在 C 语言开发中的应用&am…

二分查找5:852. 山脉数组的峰顶索引

链接&#xff1a;852. 山脉数组的峰顶索引 - 力扣&#xff08;LeetCode&#xff09; 题解&#xff1a; 事实证明&#xff0c;二分查找不局限于有序数组&#xff0c;非有序的数组也同样适用 二分查找主要思想在于二段性&#xff0c;即将数组分为两段。本体就可以将数组分为ar…

【模拟电路】稳压二极管/齐纳二极管

齐纳二极管也被称为稳压二极管,是一种特殊的二极管,其工作原理是利用PN结的反向击穿状态。在齐纳二极管中,当反向电压增加到一定程度,即达到齐纳二极管的击穿电压时,反向电流会急剧增加,但此时齐纳二极管的电压却基本保持不变。这种特性使得齐纳二极管可以作为稳压器或电…

项目周期过长,如何拆分里程碑

应对项目周期过长&#xff0c;合理拆分里程碑需要做到&#xff1a;明确项目整体目标与阶段目标、合理进行任务细分与分组、设定阶段性里程碑节点、实施有效的进度跟踪与反馈机制、灵活进行里程碑调整。其中&#xff0c;明确项目整体目标与阶段目标尤为关键。这能够帮助团队在长…

蓝桥杯刷题总结 + 应赛技巧

当各位小伙伴们看到这篇文章的时候想必蓝桥杯也快开赛了&#xff0c;那么本篇文章博主就来总结一下一些蓝桥杯的应赛技巧&#xff0c;那么依旧先来走个流程 那么接下来我们分成几个板块进行总结 首先是一些基本语法 编程语言的基本语法 首先是数组&#xff0c;在存数据的时候…

希哈表的学习

#include <stdio.h> #include <stdlib.h> #include "uthash.h"typedef struct {int id; // 学号&#xff0c;作为keychar name[20]; // 姓名&#xff0c;作为valueUT_hash_handle hh; // 必须有这个字段 } Student;Student* studen…

Qt之OpenGL使用Qt封装好的着色器和编译器

代码 #include "sunopengl.h"sunOpengl::sunOpengl(QWidget *parent) {}unsigned int VBO,VAO; float vertices[]{0.5f,0.5f,0.0f,0.5f,-0.5f,0.0f,-0.5f,-0.5f,0.0f,-0.5f,0.5f,0.0f };unsigned int indices[]{0,1,3,1,2,3, }; unsigned int EBO; sunOpengl::~sunO…

零基础开始学习鸿蒙开发-智能家居APP离线版介绍

目录 1.我的小屋 2.查找设备 3.个人主页 前言 好久不发博文了&#xff0c;最近都忙于面试&#xff0c;忙于找工作&#xff0c;这段时间终于找到工作了。我对鸿蒙开发的激情依然没有减退&#xff0c;前几天做了一个鸿蒙的APP&#xff0c;现在给大家分享一下&#xff01; 具体…

不再卡顿!如何根据使用需求挑选合适的电脑内存?

电脑运行内存多大合适&#xff1f;在选购或升级电脑时&#xff0c;除了关注处理器的速度、硬盘的容量之外&#xff0c;内存&#xff08;RAM&#xff09;的大小也是决定电脑性能的一个重要因素。但究竟电脑运行内存多大才合适呢&#xff1f;这篇文章将帮助你理解不同使用场景下适…

华为云 云化数据中心 CloudDC | 架构分析与应用场景

云化数据中心 CloudDC 云化数据中心 (CloudDC)是一种满足传统DC客户云化转型诉求的产品&#xff0c;支持将客户持有服务器设备部署至华为云机房&#xff0c;通过外溢华为云的基础设施管理、云化网络、裸机纳管、确定性运维等能力&#xff0c;帮助客户DC快速云化转型。 云化数据…

【射频仿真学习笔记】变压器参数的Mathematica计算以及ADS仿真建模

变压器模型理论分析 对于任意的无源电路或者等效电路&#xff0c;当画完原理图后&#xff0c;能否认为已经知道其中的两个节点&#xff1f;vin和vout之间的明确解析解 是否存在一个通用的算法&#xff0c;将这里的所有元素都变成了符号&#xff0c;使得这个算法本身就是一个函…

Linux系统Docker部署开源在线协作笔记Trilium Notes与远程访问详细教程

&#xfeff;今天和大家分享一款在 G 站获得了 26K的强大的开源在线协作笔记软件&#xff0c;Trilium Notes 的中文版如何在 Linux 环境使用 docker 本地部署&#xff0c;并结合 cpolar 内网穿透工具配置公网地址&#xff0c;轻松实现远程在线协作的详细教程。 Trilium Notes 是…

C++基础精讲-01

1C概述 1.1初识C 发展历程&#xff1a; C 由本贾尼・斯特劳斯特卢普在 20 世纪 70 年代开发&#xff0c;它在 C 语言的基础上增加了面向对象编程的特性&#xff0c;最初被称为 “C with Classes”&#xff0c;后来逐渐发展成为独立的 C 语言。 语言特点 &#xff08;1&#x…

为什么Java不支持多继承?如何实现多继承?

一、前言 Java不支持多继承&#xff08;一个类继承多个父类&#xff09;主要出于文中设计考虑&#xff1b;核心目的是简化语言复杂性并避免潜在的歧义性问题。 二、直接原因&#xff1a;菱形继承/钻石继承问题&#xff08;Diamond Problem&#xff09; 假设存在如下继承关系&…

[特殊字符] Spring Boot 日志系统入门博客大纲(适合初学者)

一、前言 &#x1f4cc; 为什么日志在项目中如此重要&#xff1f; 在开发和维护一个后端系统时&#xff0c;日志就像程序运行时的“黑匣子”&#xff0c;帮我们记录系统的各种行为和异常。一份良好的日志&#xff0c;不仅能帮助我们快速定位问题&#xff0c;还能在以下场景中…

Express中间件(Middleware)详解:从零开始掌握(1)

1. 中间件是什么&#xff1f; 想象中间件就像一个"加工流水线"&#xff0c;请求(Request)从进入服务器到返回响应(Response)的过程中&#xff0c;会经过一个个"工作站"进行处理。 简单定义&#xff1a;中间件是能够访问请求对象(req)、响应对象(res)和下…

现代工业测试的核心支柱:电机试验工作台?(北重机械厂家)

电机试验工作台是现代工业测试中的核心支柱之一。这种工作台通常用于对各种类型的电机进行性能测试、负载测试和耐久性测试。通过电机试验工作台&#xff0c;工程师可以评估电机的效率、功率输出、转速、扭矩、温度等关键参数&#xff0c;从而确保电机的设计符合要求&#xff0…