这篇文章主要介绍了关于如何用纯css实现一副国际象棋 ,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下
![1531299030289944.png 3035574702-5b25da43a547a_articlex[1].png](https://www.chuangxiangniao.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
源代码下载
每日前端实战系列的全部源代码请从 github 下载:
https://github.com/comehope/front-end-daily-challenges
代码解读
定义 dom,一共 8 个列表,每个列表包含 8 个元素:
居中显示:
立即学习“前端免费学习笔记(深入)”;
body { margin: 0; height: 100vh; display: flex; align-items: center; justify-content: center; background-color: darkslategray;}
定义容器的背景色和尺寸(由字号决定尺寸):
.chess { background-color: burlywood; font-size: 32px;}
画出网格状棋盘:
ul { display: table; margin: 0; padding: 0;}li { display: table-cell; width: 1.5em; height: 1.5em;}
设置网格交错的颜色:
ul:nth-child(odd) li:nth-child(even),ul:nth-child(even) li:nth-child(odd) { background-color: rgba(0, 0, 0, 0.6);}
在棋盘上安放棋子:
- ♜
- ♞
- ♝
- ♛
- ♚
- ♝
- ♞
- ♜
- ♟
- ♟
- ♟
- ♟
- ♟
- ♟
- ♟
- ♟
- ♟
- ♟
- ♟
- ♟
- ♟
- ♟
- ♟
- ♟
- ♜
- ♞
- ♝
- ♛
- ♚
- ♝
- ♞
- ♜
设置棋子的颜色:
ul:nth-child(-n+2) { color: black;}ul:nth-child(n+7) { color: white;}
最后,为棋盘增加一点立体效果:
.chess { border: 0.2em solid tan; box-shadow: 0 0.3em 2em 0.4em rgba(0, 0, 0, 0.3);}
大功告成!
以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!
相关推荐:
如何用纯CSS 实现一个颜色卡的效果
如何用纯CSS实现卡通鹦鹉的效果
以上就是如何用纯CSS实现一副国际象棋的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1610848.html
微信扫一扫
支付宝扫一扫