Good day, habrovtsy. As a result of the last article, I realized that the topic is interesting to the public, so I prepared another material, a little more complicated. There are still no scripts, only HTML / CSS.
Watch the video and under the cat.
Of course, the speech (so far) is not about a full-fledged game, but I will show the concept.
I called the game "help traffic find friends." She can do this by building a nexus and “training” her friends. Therefore, the goal of the game is to help traffic find friends. So let's go. ')
First of all, in CSS we have the whole game tied up on checkboxes and radio buttons and a slider "~". Therefore, the variable elements must be on top of the page.
Besides the fact that they should be at the top, they should not yet be inside blocks, since the selector "~" selects elements of the same level. That is, having markup
This is because .some is nested in #map, that is, at a different nesting level. In this case, the selector must start with the closest element of the same level.
#default-state-unit:checked ~ #map.some
Grid
As we all know, starcraft buildings are arranged on a grid. Accordingly, we need to make the same grid. It will consist of blocks containing certain states that this cell can assume - for example, a nexus is built on it:
<!-- --><divclass="cell-label"><!-- --><labelfor="cell_6_nexus"class="nexus status unit"><spanclass="inner"></span></label><inputtype="checkbox"id="cell_6_nexus"class="cell-state"><labelclass="view nexus unit"for="nexus-select"><divclass="probes"><divclass="probe"></div><divclass="probe"></div><divclass="probe"></div><divclass="probe"></div><divclass="probe"></div></div></label></div><!-- / -->
For the final mapping, we have the .view block (they can be many for different states). Turns on the state when you click on the corresponding label: turn on the checkbox - .view is visible:
The label itself is also visible under certain conditions. For example, when we are going to build a nexus, we have a “visible” (display: block) label responsible for this state:
When you hover over a cell, we want to see in advance how our building will stand. To do this, just stylize a label span nested (span is larger than a label, a label the size of a cell). So, we see the preliminary location of the building, but the block and the image close the neighboring cells, so that it is difficult to beat the state on them: hover (which just initiates the display of the preliminary construction). Glory to the gods, we can already use the CSS4 property
pointer-events: none;
This property allows you to disable the response of the block to mouse events, as if to make it transparent for the mouse. Neither click nor hover element is perceived. Even select an element using a magnifying glass from the developer panel is impossible. At the same time, he is quite visible to himself exactly at the z-level at which he should.
Units
We have several units and buildings, and highlighting each of these elements, we want to see different buttons on the taskbar. This is achieved by switching the radio buttons, because each time we can select only one building / unit (in the original, not so).
Conclusion
I wanted to do some reset to the default states of some radio buttons that are responsible for the state of the panel when a unit / building is selected. I put the label in the label in the label hoping that clicking on the contents of the label will cause a click on the container. But to my surprise it did not work, only the internal label is clicked.