2017-01-10 20 views
0

我想制作一个Gomoku游戏。董事会看起来像一个规则的网格,除了件被放置在十字路口而不是空间。CSS,在按钮上添加线条和形状?

looks like this

到目前为止,我有这样的tic-tac-toe example从Reactjs教程网格。

从它相关的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; 
} 

他们使按钮,每个空间是按钮的网格。不过,我需要让我的交叉点可点击,而不是空格。我打算制作这样的按钮,例如my buttons,以便制作电路板。蓝色边框将不可见,我将它们画成清晰可见的每个按钮。最后一个黑圈是在路口玩的一块。

如何将这些线条和圆圈添加到我的按钮?还是有更好的方法来做到这一点?谢谢。

回答

1

好,如果你有一个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

1

用作容器flexboxpaddingflex-wrap: wrap。现在,您只需渲染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>