你竟然是这么神奇的 CSS

程序员成长指北

共 10595字,需浏览 22分钟

 · 2021-12-28


曾闻巨佬云,CSS者,码农家之装潢也。远观之,如风静而縠纹平;细察之,如瑰石而灵光耀。相传遗留三十余物称之静姝,后人拾其贡之于堂,以图庇佑其子嗣,显名于四方,通达其祖技,居功其庙堂。

大厂技术  高级前端  Node进阶

点击上方 程序员成长指北,关注公众号

回复1,加入高级Node交流群

前言

相信大家都听到过“能用CSS实现的就别用图片”这句话,毕竟CSS代码的体积比图片要小得多。那么今天就给大家分享30个 CSS 静态形状,希望各位小伙伴喜欢❤️。

代码

1. 椭圆

椭圆.png
.oval {
    width200px;
    height100px;
    background-color: skyblue;
    border-radius100px / 50px;
}
复制代码

2. 上三角

上三角.png
.triangle-up {
    width0;
    height0;
    border-right50px solid transparent;
    border-bottom100px solid skyblue;
    border-left50px solid transparent;
}
复制代码

3. 下三角

下三角.png
.triangle-down {
    width0;
    height0;
    border-top100px solid skyblue;
    border-right50px solid transparent;
    border-left50px solid transparent;
}
复制代码

4. 左三角

左三角.png
.triangle-left {
    width0;
    height0;
    border-top50px solid transparent;
    border-right100px solid skyblue;
    border-bottom50px solid transparent;
}
复制代码

5. 右三角

右三角.png
.triangle-right {
    width0;
    height0;
    border-top50px solid transparent;
    border-bottom50px solid transparent;
    border-left100px solid skyblue;
}
复制代码

6. 左上角

左上角.png
.triangle-topleft {
    width0;
    height0;
    border-top100px solid skyblue;
    border-right100px solid transparent;
}
复制代码

7. 右上角

右上角.png
.triangle-topright {
    width0;
    height0;
    border-top100px solid skyblue;
    border-left100px solid transparent;
}
复制代码

8. 左下角

左下角.png
.triangle-bottomleft {
    width0;
    height0;
    border-right100px solid transparent;
    border-bottom100px solid skyblue;
}
复制代码

9. 右下角

右下角.png
.triangle-bottomright {
    width0;
    height0;
    border-bottom100px solid skyblue;
    border-left100px solid transparent;
}
复制代码

10. 箭头

箭头.png
.curvedarrow {
    position: relative;
    width0;
    height0;
    border-top9px solid transparent;
    border-right9px solid skyblue;
    transformrotate(10deg);
}

.curvedarrow:after {
    position: absolute;
    top: -12px;
    left: -9px;
    width12px;
    height12px;
    content'';
    border0 solid transparent;
    border-top3px solid skyblue;
    border-radius20px 0 0 0;
    transformrotate(45deg);
}
复制代码

11. 平行四边形

平行四边形.png
.parallelogram {
    width100px;
    height100px;
    background-color: skyblue;
    transformskew(20deg);
}
复制代码

12. 梯形

梯形.png
.trapezoid {
    width100px;
    height0;
    border-right25px solid transparent;
    border-bottom100px solid skyblue;
    border-left25px solid transparent;
}
复制代码

13. 五边形

五边形.png
.pentagon {
    position: relative;
    width54px;
    border-width50px 18px 0;
    border-style: solid;
    border-color: skyblue transparent;
    box-sizing: content-box;
}

.pentagon:before {
    position: absolute;
    top: -85px;
    left: -18px;
    height0;
    width0;
    content'';
    border-width0 45px 35px;
    border-style: solid;
    border-color: transparent transparent skyblue;
}
复制代码

14. 六边形

六边形.png
.hexagon {
    position: relative;
    width100px;
    height55px;
    background-color: skyblue;
}

.hexagon:before {
    position: absolute;
    top: -25px;
    left0;
    width0;
    height0;
    content'';
    border-right50px solid transparent;
    border-bottom25px solid skyblue;
    border-left50px solid transparent;
}

.hexagon:after {
    position: absolute;
    bottom: -25px;
    left0;
    width0;
    height0;
    content'';
    border-top25px solid skyblue;
    border-right50px solid transparent;
    border-left50px solid transparent;
}
复制代码

15. 爱心 ❤️

爱心.png
.heart {
    position: relative;
    width100px;
    height90px;
}

.heart:before,
.heart:after {
    position: absolute;
    left50px;
    top0;
    width50px;
    height80px;
    content'';
    background-color: skyblue;
    border-radius50px 50px 0 0;
    transformrotate(-45deg);
    transform-origin0 100%;
}

.heart:after {
    left0;
    transformrotate(45deg);
    transform-origin100% 100%;
}
复制代码

16. 无穷大

无穷大.png
.infinity {
    position: relative;
    width150px;
    height100px;
    box-sizing: content-box;
}

.infinity:before,
.infinity:after {
    position: absolute;
    top0;
    left0;
    width30px;
    height30px;
    content'';
    border20px solid skyblue;
    border-radius50px 50px 0 50px;
    box-sizing: content-box;
    transformrotate(-45deg);
}

.infinity:after {
    left: auto;
    right0;
    border-radius50px 50px 50px 0;
    transformrotate(45deg);
}
复制代码

17. 钻石 💎

钻石.png
.diamond {
    position: relative;
    width50px;
    height0;
    border-width0 25px 25px 25px;
    border-style: solid;
    border-color: transparent transparent skyblue transparent;
    box-sizing: content-box;
}

.diamond:after {
    position: absolute;
    top25px;
    left: -25px;
    width0;
    height0;
    content'';
    border-width70px 50px 0 50px;
    border-style: solid;
    border-color: skyblue transparent transparent transparent;
}
复制代码

18. 锁 🔒

锁.png
.lock {
    position: relative;
    width90px;
    height65px;
    border18px solid skyblue;
    border-right-width37px;
    border-left-width37px;
    border-radius10px;
    box-sizing: border-box;
}

.lock:before {
    position: absolute;
    top: -60px;
    left50%;
    width70px;
    height60px;
    content'';
    border12px solid skyblue;
    border-top-left-radius35px;
    border-top-right-radius35px;
    box-sizing: border-box;
    transformtranslateX(-50%);
}

.lock:after {
    position: absolute;
    top: -5px;
    left50%;
    width25px;
    height40px;
    content'';
    border5px solid skyblue;
    border-radius12px;
    box-sizing: border-box;
    transformtranslateX(-50%);
}
复制代码

19. 吃豆人

吃豆人.png
.pacman {
    width0px;
    height0px;
    border60px solid skyblue;
    border-right60px solid transparent;
    border-radius60px;
}
复制代码

20. 对话泡泡

对话泡泡.png
.talkbubble {
    position: relative;
    width120px;
    height80px;
    background-color: skyblue;
    border-radius10px;
}

.talkbubble:before {
    position: absolute;
    top26px;
    right100%;
    width0;
    height0;
    content'';
    border-top13px solid transparent;
    border-right26px solid skyblue;
    border-bottom13px solid transparent;
}
复制代码

21. 太极

太极.png
.supremepole {
    position: relative;
    width96px;
    height48px;
    background-color#fff;
    border-width2px 2px 50px 2px;
    border-style: solid;
    border-color#000;
    border-radius50%;
    box-sizing: content-box;
}

.supremepole:before {
    position: absolute;
    top50%;
    left0;
    width12px;
    height12px;
    content'';
    background-color#fff;
    border18px solid #000;
    border-radius50%;
    box-sizing: content-box;
}

.supremepole:after {
    position: absolute;
    top50%;
    left50%;
    width12px;
    height12px;
    content'';
    background-color#000;
    border18px solid #fff;
    border-radius50%;
    box-sizing: content-box;
}
复制代码

22. 丝带徽章

丝带徽章.png
.badge-ribbon {
    position: relative;
    height100px;
    width100px;
    background-color: skyblue;
    border-radius50%;
}

.badge-ribbon:before,
.badge-ribbon:after {
    position: absolute;
    top70px;
    left: -10px;
    content'';
    border-right40px solid transparent;
    border-bottom70px solid skyblue;
    border-left40px solid transparent;
    transformrotate(-140deg);
}

.badge-ribbon:after {
    right: -10px;
    left: auto;
    transformrotate(140deg);
}
复制代码

23. 雪佛兰车标

雪佛兰车标.png
.chevrolet {
    position: relative;
    width140px;
    height50px;
}

.chevrolet:before {
    position: absolute;
    top0;
    left0;
    width50%;
    height100%;
    content'';
    background-color: skyblue;
    transformskew(0deg6deg);
}

.chevrolet:after {
    position: absolute;
    top0;
    right0;
    width50%;
    height100%;
    content'';
    background-color: skyblue;
    transformskew(0deg, -6deg);
}
复制代码

24. 放大镜 🔍

放大镜.png
.magnifying-glass {
    position: relative;
    width0.4em;
    height0.4em;
    font-size10em;
    border0.1em solid skyblue;
    border-radius0.35em;
    box-sizing: content-box;
}

.magnifying-glass:before {
    position: absolute;
    right: -0.25em;
    bottom: -0.1em;
    width0.35em;
    height0.08em;
    content'';
    background-color: skyblue;
    transformrotate(45deg);
}
复制代码

25. Facebook 图标

Facebook 图标.png
.facebook-icon {
    position: relative;
    width100px;
    height110px;
    background-color: skyblue;
    border15px solid skyblue;
    border-bottom0;
    border-radius5px;
    box-sizing: content-box;
    overflow: hidden;
}

.facebook-icon:before {
    position: absolute;
    right: -37px;
    bottom: -30px;
    width40px;
    height90px;
    content'';
    background-color: skyblue;
    border20px solid #fff;
    border-radius25px;
    box-sizing: content-box;
}

.facebook-icon:after {
    position: absolute;
    top50px;
    right5px;
    width55px;
    height20px;
    content'';
    background-color#fff;
    box-sizing: content-box;
}
复制代码

26. 月亮 🌙

月亮.png
.moon {
    width80px;
    height80px;
    border-radius50%;
    box-shadow15px 15px 0 0 skyblue;
}
复制代码

27. 圆锥

圆锥.png
.cone {
    width0;
    height0;
    border-top100px solid skyblue;
    border-right70px solid transparent;
    border-left70px solid transparent;
    border-radius50%;
}
复制代码

28. 十字架

十字架.png
.cross {
    position: relative;
    width20px;
    height100px;
    background-color: skyblue;
}

.cross:before {
    position: absolute;
    top40px;
    left: -40px;
    width100px;
    height20px;
    content"";
    background-color: skyblue;
}
复制代码

29. 谷堆

谷堆.png
.base {
    position: relative;
    width100px;
    height55px;
    background-color: skyblue;
}

.base:before {
    position: absolute;
    top: -35px;
    left0;
    width0;
    height0;
    content'';
    border-right50px solid transparent;
    border-bottom35px solid skyblue;
    border-left50px solid transparent;
}
复制代码

30. 指示器

指示器.png
.pointer {
    position: relative;
    width120px;
    height40px;
    background-color: skyblue;
}

.pointer:before {
    position: absolute;
    bottom0;
    left0;
    width0;
    height0;
    content'';
    border-top20px solid transparent;
    border-bottom20px solid transparent;
    border-left20px solid #fff;
}

.pointer:after {
    position: absolute;
    right: -20px;
    bottom0;
    width0;
    height0;
    content'';
    border-top20px solid transparent;
    border-bottom20px solid transparent;
    border-left20px solid skyblue;
}
复制代码

结语

合抱之木生于毫末,九尺之台起于累土。对于技术的提升,我们要有足够的耐心,去一点一点的积累,等到一定程度,必然会有质变。毕竟事需缓图,欲速不达也。


关于本文

作者:冰冰你个小可爱

https://juejin.cn/post/7017772634704183304

Node 社群


我组建了一个氛围特别好的 Node.js 社群,里面有很多 Node.js小伙伴,如果你对Node.js学习感兴趣的话(后续有计划也可以),我们可以一起进行Node.js相关的交流、学习、共建。下方加 考拉 好友回复「Node」即可。


   “分享、点赞在看” 支持一波👍

浏览 12
点赞
评论
收藏
分享

手机扫一扫分享

举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

举报