body { text-align: center; margin: 0; } .tic-tac-toe { height: 450px; width: 450px; margin: 50px auto 30px auto; position: relative; background-color: #E6E6FA; } .tic-tac-toe label { background-color: #78bec5; height: 140px; width: 140px; display: none; margin: 5px; position: absolute; cursor: pointer; color: #fff; -moz-transition: background-color 0.3s; -o-transition: background-color 0.3s; -webkit-transition: background-color 0.3s; transition: background-color 0.3s; } .tic-tac-toe input.col-0 + label { left: 0px; right: 300px; } .tic-tac-toe input.col-1 + label { left: 150px; right: 150px; } .tic-tac-toe input.col-2 + label { left: 300px; right: 0px; } .tic-tac-toe input.row-0 + label { top: 0px; bottom: 300px; } .tic-tac-toe input.row-1 + label { top: 150px; bottom: 150px; } .tic-tac-toe input.row-2 + label { top: 300px; bottom: 0px; } .tic-tac-toe input { display: none; } .tic-tac-toe input.turn-0 + label { z-index: 0; display: block; } {% for turn in turns_player %} .tic-tac-toe input.turn-{{turn}}:checked + label { cursor: default; background-color: red; z-index: 10 !important; } .tic-tac-toe input.turn-{{turn}}:checked ~ .turn-{{turn + 2}} + label { z-index: {{turn + 2}}; display: block; } {% endfor %} {% for m in moves %} .tic-tac-toe {% for p in m.ps %}input.turn-{{p.t}}.field-{{p.i}}:checked ~ {% endfor %} input.turn-{{m.n.t}}.field-{{m.n.i}} + label { display: block; cursor: default; background-color: green; z-index: 10 !important; } {% endfor %}