700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > HTML5绘制国际象棋 如何用纯CSS实现一副国际象棋

HTML5绘制国际象棋 如何用纯CSS实现一副国际象棋

时间:2019-09-20 11:59:49

相关推荐

HTML5绘制国际象棋 如何用纯CSS实现一副国际象棋

这篇文章主要介绍了关于如何用纯CSS实现一副国际象棋 ,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下

源代码下载

每日前端实战系列的全部源代码请从 github 下载:

/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中文网!

相关推荐:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。