我在试着做一个五子棋游戏。棋盘看起来像是一个规则的网格,只是棋子被放置在交叉点上而不是空间上。

到目前为止,我有一个类似于Reactjs教程中的tic-tac-toe example的网格。
来自它的相关CSS是:
.board-row:after {
clear: both;
content: "";
display: table;
}
.square {
background: #fff;
border: 1px solid #999;
float: left;
font-size: 24px;
font-weight: bold;
line-height: 34px;
height: 34px;
margin-right: -1px;
margin-top: -1px;
padding: 0;
text-align: center;
width: 34px;
}
.square:focus {
outline: none;
}他们制作了一个按钮网格,其中每个空格都是一个按钮。然而,我需要让我的交叉点可点击,而不是空间。我正计划制作像这样的按钮

这是为了制作棋盘。蓝色的边框将是不可见的,我画了它们来清楚地看到每个按钮。最后一个中的黑色圆圈是在交叉点上演奏的一块。
如何将这些线条和圆圈添加到我的按钮?或者有更好的方法来做这件事?谢谢。
发布于 2017-01-11 00:59:23
如果你有一个div,你可以做到这一点
div {
width: 100px;
height: 100px;
position: relative;
outline: 1px solid red;
}
div:after{
content: '';
position: absolute;
background-color: black;
top:0;
bottom: 0;
left: 45px;
right: 45px;
}
div:before{
content: '';
position: absolute;
background-color: black;
top:45px;
bottom: 45px;
left: 0;
right: 0;
}工作示例http://jsbin.com/mupucurebi/edit?html,css,js,output
发布于 2017-01-11 01:59:51
使用带有padding和flex-wrap: wrap的flexbox作为容器。现在你要做的就是渲染64个大小合适的元素。
此外,您还可以使用渐变图案作为背景。背景基于enjoycss中的模式。
const { render } = ReactDOM;
const Board = () => (
<div className="bg">
{
Array.from({ length: 64 }, (i, k) => (
<div key={ k } className="piece" />
))
}
</div>
);
render(
<Board />,
document.getElementById('root')
);body {
margin: 0;
padding: 2px;
}
.bg {
display: flex;
flex-wrap: wrap;
box-sizing: content-box;
width: 272px;
height: 269px;
padding: 14px 16px;
border: none;
color: rgba(255,255,255,1);
text-overflow: clip;
background: linear-gradient(0deg, #000000 0, #FFFFFF 2px, rgba(0,0,0,0) 2px, rgba(0,0,0,0) 100%), linear-gradient(90deg, #000000 0, #FFFFFF 2px, rgba(0,0,0,0) 2px, rgba(0,0,0,0) 100%), rgba(255,255,255,1);
background-position: -2px -2px;
background-clip: border-box;
background-size: 34px 34px;
}
.piece {
width: 30px;
height: 30px;
margin: 2px;
border-radius: 50%;
background: blue;
}<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.min.js"></script>
<div id="root"></div>
https://stackoverflow.com/questions/41574095
复制相似问题