Check out Makruk (Thai Chess), our featured variant for March, 2025.

Enter Your Reply

The Comment You're Replying To
H. G. Muller wrote on Thu, Apr 24 04:53 AM EDT in reply to Fergus Duniho from Wed Apr 23 07:39 PM:

I was not aware of this grid style at all. But after some reading up on it, it seems that it is pretty easy to mimic a HTML <table> with a HTML <div> element defined as container, and replace the <td> elements in it by <div> elements. The <tr> level can be omitted entirely, as the length of each table row is implied by the container <div> through its columns template. This is good, because it means there would hardly have to be any change in the current code to use a grid instead of a table. The <td> attribute colspan (which the I.D. only uses for the upper board rim) has an analog in the grid as well.

In detail: the board table currently is defined as

<table id="board' + dnr + '"
       cellpadding="0"
       style="
              border-collapse:collapse'
              + (background ? ';background-image:url(' + background + ')' : '') + '
             "'
       + (coords < 0 ? ' border="1"' : '') +'
       oncontextmenu="return false;"
   ></table>                               // initially empty

The cellpadding seems to become redundant, as the <div> daughters by default would have zero padding, unlike the <td> granddaughters. I have no doubt that a <div> would also support oncontextmenu and a background-image. That leaves the border-collapse style; I suppose the corresponding grid attribute is the column-gap. I am not sure whether setting that to 0 and giving the <div> daughters a border of 1px would make the borders coincide, or whether this would require column-gap to be 1 or -1.

In addition the container would need the style display:grid. The width and height attributes of the <td> elements would be moved to the container <div> as grid-template-columns and grid-template-rows. Cells for the board rim contain (apart from the now redundant height and width styles) only styles for their background and text coloring and alignment.(And in one case a colspan="N", which would become a column-start: 1/span N style.)

It looks like a simple patch; I will try it out.

The <td> elements for the board squares are currently defined with attributes

valign="center"
align="center"
style="
     width:' + sqrSize + 'px;
     height:' + sqrSize + 'px' + ';
     border:' + bb + ';                     // bb = (borders ? 'thin solid black' : 'none');
     font-size:xx-large;
     background-repeat:no-repeat;
     background-position: center center;
     background-size:contain
     "
onmousedown="Down(' + bnr + ',' + j + ',' + h + ',event)"
onmouseup="Up(' + bnr + ',' + j + ',' + h + ',event)"
ontouch="Touch(' + bnr + ',' + j + ',' + h + ')"
onmouseover="Hover(event)"
ondragover="PreDrop(event)"
ondrop="Drop(event)"
ondragend="Relay(event)"

All the handlers would no doubt also work on a <div> element. I am not sure the align and valign HTML attributes would work on a <div>; they might have to be replaced by corresponding style specs. (These serve to position the move-highlighting marker images, which are cell content.) As for the styles, I think border works fine on a <div>, as well as font-size (needed only to display question marks in move diagrams to indicate hidden hopper moves when color highlighting is used). The background details should work too, as <div> elements can have background images. (The actual background-image (of the piece) would be set by Display().) So it is basically a matter of replacing the width and height styles (now handled by the container templates) by style instructions needed to center the content.


Edit Form

Comment on the page Xiangqi: Chinese Chess

Conduct Guidelines
This is a Chess variants website, not a general forum.
Please limit your comments to Chess variants or the operation of this site.
Keep this website a safe space for Chess variant hobbyists of all stripes.
Because we want people to feel comfortable here no matter what their political or religious beliefs might be, we ask you to avoid discussing politics, religion, or other controversial subjects here. No matter how passionately you feel about any of these subjects, just take it someplace else.
Avoid Inflammatory Comments
If you are feeling anger, keep it to yourself until you calm down. Avoid insulting, blaming, or attacking someone you are angry with. Focus criticisms on ideas rather than people, and understand that criticisms of your ideas are not personal attacks and do not justify an inflammatory response.
Quick Markdown Guide

By default, new comments may be entered as Markdown, simple markup syntax designed to be readable and not look like markup. Comments stored as Markdown will be converted to HTML by Parsedown before displaying them. This follows the Github Flavored Markdown Spec with support for Markdown Extra. For a good overview of Markdown in general, check out the Markdown Guide. Here is a quick comparison of some commonly used Markdown with the rendered result:

Top level header: <H1>

Block quote

Second paragraph in block quote

First Paragraph of response. Italics, bold, and bold italics.

Second Paragraph after blank line. Here is some HTML code mixed in with the Markdown, and here is the same <U>HTML code</U> enclosed by backticks.

Secondary Header: <H2>

  • Unordered list item
  • Second unordered list item
  • New unordered list
    • Nested list item

Third Level header <H3>

  1. An ordered list item.
  2. A second ordered list item with the same number.
  3. A third ordered list item.
Here is some preformatted text.
  This line begins with some indentation.
    This begins with even more indentation.
And this line has no indentation.

Alt text for a graphic image

A definition list
A list of terms, each with one or more definitions following it.
An HTML construct using the tags <DL>, <DT> and <DD>.
A term
Its definition after a colon.
A second definition.
A third definition.
Another term following a blank line
The definition of that term.