当前位置:首页 > CSS

css制作小猪

2026-01-28 05:39:47CSS

使用CSS绘制小猪

以下是通过纯CSS绘制卡通小猪的代码示例,结合圆形、椭圆形和阴影效果实现:

<!DOCTYPE html>
<html>
<head>
    <style>
        .pig {
            position: relative;
            width: 200px;
            height: 180px;
            margin: 50px auto;
        }

        /* 头部 */
        .head {
            width: 160px;
            height: 140px;
            background: pink;
            border-radius: 50%;
            position: relative;
        }

        /* 耳朵 */
        .ear {
            width: 40px;
            height: 60px;
            background: pink;
            border-radius: 50%;
            position: absolute;
            top: -20px;
        }
        .ear.left {
            left: 20px;
            transform: rotate(-30deg);
        }
        .ear.right {
            right: 20px;
            transform: rotate(30deg);
        }

        /* 眼睛 */
        .eye {
            width: 20px;
            height: 30px;
            background: white;
            border-radius: 50%;
            position: absolute;
            top: 50px;
        }
        .eye.left {
            left: 40px;
        }
        .eye.right {
            right: 40px;
        }
        .eye::after {
            content: '';
            width: 10px;
            height: 10px;
            background: black;
            border-radius: 50%;
            position: absolute;
            bottom: 5px;
            left: 5px;
        }

        /* 鼻子 */
        .nose {
            width: 50px;
            height: 30px;
            background: #ff99aa;
            border-radius: 50%;
            position: absolute;
            bottom: 40px;
            left: 55px;
        }
        .nose::before, .nose::after {
            content: '';
            width: 8px;
            height: 8px;
            background: black;
            border-radius: 50%;
            position: absolute;
            top: 10px;
        }
        .nose::before {
            left: 10px;
        }
        .nose::after {
            right: 10px;
        }
    </style>
</head>
<body>
    <div class="pig">
        <div class="head">
            <div class="ear left"></div>
            <div class="ear right"></div>
            <div class="eye left"></div>
            <div class="eye right"></div>
            <div class="nose"></div>
        </div>
    </div>
</body>
</html>

关键实现技巧

使用圆形边框半径创建头部和耳朵的基本形状:

border-radius: 50%;

通过伪元素添加细节(如眼睛瞳孔和鼻孔):

.eye::after {
    content: '';
    /* 其他样式 */
}

使用绝对定位精确放置各个部位:

position: absolute;
top: 50px;
left: 40px;

进阶优化建议

添加阴影增强立体感:

box-shadow: inset 5px 5px 10px rgba(0,0,0,0.1);

增加动画效果使小猪更生动:

@keyframes breathe {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}
.head {
    animation: breathe 2s infinite;
}

调整颜色渐变使更逼真:

css制作小猪

background: linear-gradient(to bottom, #ffb6c1, #ff69b4);

标签: 小猪css
分享给朋友:

相关文章

css表单制作

css表单制作

基础表单结构 使用HTML创建表单的基本结构,包含<form>标签及输入字段。表单通常需要action(提交地址)和method(提交方法)属性。 <form action="/s…

如何制作css

如何制作css

创建CSS文件 新建一个纯文本文件,将文件扩展名改为.css,例如style.css。确保文件名不含空格或特殊字符,使用连字符或下划线分隔单词。 编写CSS语法 CSS规则由选择器和声明块组成。选择…

css焦点图制作

css焦点图制作

使用纯CSS制作焦点图 通过CSS的动画和过渡效果实现简单焦点图轮播,无需JavaScript。以下是一个基础实现方案: <div class="slider"> <div c…

css怎么制作表单

css怎么制作表单

基础表单结构 使用HTML创建表单元素,搭配CSS进行样式设计。表单通常包含<form>标签及输入控件(如<input>、<textarea>、<select…

css制作tkd

css制作tkd

CSS 制作 TKD(Title, Keywords, Description) TKD(Title, Keywords, Description)是网页 SEO 优化的核心元素,通常通过 HTML…

div css制作导航

div css制作导航

导航栏的基本结构 使用HTML的<nav>标签包裹导航链接,内部通常采用无序列表<ul>和列表项<li>结构。示例代码如下: <nav> <…