41.纯 CSS 绘制一支栩栩如生的铅笔

原文地址: https://segmentfault.com/a/1190000015153865

感想: 不难

HTML code:

<div class="pencil">
    <!-- taper : 笔尖 -->
    <span class="taper"></span>
    <!--barrel : 笔筒 -->
    <span class="barrel">Think Different</span>
    <!--eraser : 橡皮擦 -->
    <span class="eraser"></span>
</div>

CSS code:

html, body {
    margin: 0;
    padding: 0;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: lightskyblue;
}
.pencil{
    position: relative;
    font-size: 10px;
    width: 50em;
    height: 3.5em;
    filter: drop-shadow(5px 10px 3px gray);
}
/* 笔筒完成 */
.pencil .barrel{
    position: absolute;
    width: 40em;
    left: 4em;
    background-color: green;
    border-top: 1em solid forestgreen;
    border-bottom: 1em solid darkgreen;
    color: silver;
    line-height: 1.5em;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}
/* 笔尖 边框四部分中右边那部分*/
.pencil .taper::before,
.pencil .taper::after{
    content: '';
    position: absolute;
    left: -4em;
    border-style: solid;
    border-width: calc(3.5em / 2) 4em;
}
.pencil .taper::before{
    /* transparent : 透明的 ; biak*/
    border-color: transparent burlywood transparent transparent;
}
.pencil .taper::after{
    border-color: transparent black transparent transparent;
    transform: scale(0.3);
}
/* 橡皮擦 */
.pencil .eraser{
    position: absolute;
    right: 0;
    width: 6em;
    height: 1.5em;
    background-color: lightpink;
    border-top: 1em solid pink;
    border-bottom: 1em solid lightcoral;
    border-top-right-radius: 0.5em;
    border-top-right-radius: 0.5em;
}
.pencil .eraser::before{
    content: '';
    position: absolute;
    top: -1em;
    left: 0;
    width: 1.5em;
    height: 1.5em;
    background-color: silver;
    border-top: 1em solid lightgray;
    border-bottom: 1em solid gray;
}

 

posted on 2019-02-25 23:13 人生与戏 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/FlyingLiao/p/10434557.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值