如何用纯 CSS 创作一只愤怒小鸟中的绿猪

如何用纯 CSS 创作一只愤怒小鸟中的绿猪

实现步骤

定义 dom,容器中包含 3 个元素,分别代表耳朵、眼睛、鼻子:

<div class="pig">
    <span class="ears"></span>
    <span class="eyes"></span>
    <span class="nose"></span>
</div>

居中显示:

body {
   
    margin: 0;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: skyblue;
}

设置伪元素的共有属性,后面有多处用到伪元素:

.pig::before,
.pig::after,
.pig *::before,
.pig *::after {
   
    content: '';
    position: absolute;
}

定义容器尺寸:

.pig {
   
    width: 12em;
    height: 10em;
    font-size: 20px;
    background-color: #50a032;
    border: 0.2em solid #2b4d13;
}

用圆角属性画出头部轮廓:

.pig {
   
    border-radius: 50% 50% 50% 50% / 55% 60% 40% 45%;
}

以前以为border-radius只能设置四个角,实际上可以设置八条边。

画出鼻子的轮廓:

.pig 
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值