当前位置:首页 > 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%;

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

css制作小猪

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

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

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

进阶优化建议

添加阴影增强立体感:

css制作小猪

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;
}

调整颜色渐变使更逼真:

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

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

相关文章

css制作教程

css制作教程

CSS 基础概念 CSS(层叠样式表)用于控制网页的视觉表现,包括布局、颜色、字体等。它与HTML结合使用,HTML负责结构,CSS负责样式。 基本语法结构 CSS规则由选择器和声明块组成:…

css动画制作

css动画制作

CSS动画制作方法 使用@keyframes规则定义动画序列,通过animation属性将动画应用到元素上。以下是一个基础示例: @keyframes fadeIn { from { opaci…

css制作图片

css制作图片

CSS 制作图片的方法 使用 background-image 属性 通过 background-image 属性可以为元素设置背景图片。这种方法适用于将图片作为背景而非内容的一部分。 .elem…

css制作标尺

css制作标尺

使用CSS制作标尺的方法 方法一:使用线性渐变和伪元素 通过CSS的线性渐变和伪元素可以创建水平或垂直标尺。以下是一个水平标尺的示例代码: .ruler { width: 100%; he…

css 制作目录

css 制作目录

CSS 制作目录的方法 使用 CSS 可以轻松为网页内容创建美观且功能性的目录。以下是几种常见方法: 使用 ul 和 li 创建基础目录结构 <div class="toc">…

css制作扇形

css制作扇形

使用 CSS 制作扇形 方法一:利用 border-radius 和 transform 通过设置 border-radius 和 transform 属性,可以创建一个扇形。以下是一个示例代码:…