6. Use red, yellow, and blue to color each square of a $3 \times 3$ grid, such that:
(1) each row contains all three colors,
(2) each column contains all three colors,
(3) adjacent squares (squares sharing a common edge) are different colors.
Then the number of different coloring methods is ( ) kinds.
(A) 12
(B) 18
(C) 24
(D) 27
6.A.

Let $A$, $B$, and $C$ represent the colors red, yellow, and blue, respectively. For convenience, we number the cells $1, 2, \cdots, 9$ (as shown in Figure 2). Consider the three coloring methods for the top-left corner $B$, $C$. First, assume that cell 1 is colored $A$: $A$, then the colors of cells 2 and 4 are determined.

Once the colors of cells 1, 2, and 4 are determined, the colors of the other cells are uniquely determined. This is because each row and each column must contain all three colors, so the colors of cells 3 and 7 are determined.

Furthermore, since the number of colors used in the sets $\{2,3\}$ and $\{5,6\}$ is less than or equal to 3, one color must be used twice. To avoid adjacent cells of the same color, there is only one way to color cells 5 and 6. Once the first two rows are colored, the colors of the cells in the third row are uniquely determined.
Thus, when cell 1 is colored $A$, there are 4 ways to color the entire grid.
By symmetry, when cell 1 is colored $B$ or $C$, there are also 4 ways to color the entire grid. Therefore, there are a total of 12 ways to color the grid.