Create a chessboard with a border using only HTML and CSS

I recently completed a chessboard using only HTML and CSS, but I am facing a challenge as I attempt to add a frame around the board. Since I lack design skills, I am struggling to achieve this simple task. I have tried utilizing the CSS border property within the table.chessboard element (see code below), however, the margin seems to be expanding inside the board and shrinking the squares along the borders.

Does anyone have any suggestions on how I can resolve this issue?

Code:

table.chessboard {
  margin: 80px auto;
  background: #999;
  border: 25px solid #333;
}

td.chessboard {
  width: 70px;
  height: 70px;
}

tr.chessboard:nth-child(odd) td.chessboard:nth-child(even),
tr.chessboard:nth-child(even) td.chessboard:nth-child(odd) {
  background: white;
}
<table class="chessboard">
  <tr class="chessboard">
    <td class="chessboard"></td>
    <!-- line above 8 times -->
  </tr>
  <tr class="chessboard">
    <td class="chessboard"></td>
    <!-- line above 8 times -->
  </tr>
  <tr class="chessboard">
    <td class="chessboard"></td>
    <!-- line above 8 times -->
  </tr>
  <tr class="chessboard">
    <td class="chessboard"></td>
    <!-- line above 8 times -->
  </tr>
  <tr class="chessboard">
    <td class="chessboard"></td>
    <!-- line above 8 times -->
  </tr>
  <tr class="chessboard">
    <td class="chessboard"></td>
    <!-- line above 8 times -->
  </tr>
  <tr class="chessboard">
    <td class="chessboard"></td>
    <!-- line above 8 times -->
  </tr>
  <tr class="chessboard">
    <td class="chessboard"></td>
    <!-- line above 8 times -->
  </tr>
</table>

Answer №1

If I had to guess, you're looking to create a border around each cell.

table.chessboard {
    margin: 80px auto;
    background: #999;
    border: 25px solid #333;
    border-collapse: collapse; /* */
}
td.chessboard {
    width: 70px; height: 70px;
    border: 2px solid #333; /* */
}
tr.chessboard:nth-child(odd) td.chessboard:nth-child(even),
tr.chessboard:nth-child(even) td.chessboard:nth-child(odd) {
    background: white;
}
<table class="chessboard">
<tr class="chessboard">
    <td class="chessboard"></td>
    <td class="chessboard"></td>
    <td class="chessboard"></td>
    <td class="chessboard"></td>
    <td class="chessboard"></td>
    <td class="chessboard"></td>
    <td class="chessboard"></td>
    <td class="chessboard"></td>
</tr>

...

Answer №2

When styling your website:

table.chessboard { 
   border: 2px solid #000;
}

Feel free to customize the width to your liking ;)

Answer №3

Creating a Chessboard with HTML and CSS

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

defiant underscore refusing to function

I'm currently working on a text editor, but I'm facing an issue with the remove underline functionality that doesn't seem to be working as expected. For reference, you can check out a working code example here: jsfiddle Below is the part of ...

Can the color of the expanded navigation bar in Bootstrap 4 be customized?

I'm currently in the process of developing a Bootstrap website and was wondering whether it is feasible to add a background color to the expanded navbar specifically on small screens. Feel free to refer to the images below for a visual representation ...

Exploring the power of Bootstrap 5 for vertical alignment

I am currently utilizing the flexbox grid from Bootstrap 5 to create a mobile-first Angular web application that is responsive. For the home screen of my app, I want to incorporate these 3 elements : The title of the app displayed at the top A series of ...

Changing the color of HTML text based on a variable in Vue JS can be achieved by altering the CSS styles dynamically

I have developed a website that shows values with a set threshold. I now want to change the color of the values when they exceed the threshold, but I am unsure of how to proceed. I want to display consultation.indicateurs.TRS in red when it exceeds the va ...

Send the selected option from the dropdown menu to a different page

I am in the process of designing a unique shopping cart system where, upon clicking on the "add to cart" link, both the selected quantity from the drop-down menu and the product ID are transmitted to the addCart page. While I have successfully managed to p ...

The CSS styles do not seem to be taking effect on the Bootstrap

Here's a snippet of code extracted from my website's html and css files. My intention is to make the navbar slightly transparent with centered links, but for some reason, the css styles are not applying correctly to the navbar. HTML <body ...

Differences in Print Layout Between Chrome and Firefox when Viewing a PHP Website

I have been working on creating a print command to print a specific div, and I have managed to successfully run the print command using default methods like CTRL + P and also with a button click. The Issue: However, I have encountered a problem where the ...

What is the best way to interpret numerous rows of Form elements simultaneously?

What is the most efficient way to name form elements across rows for easy conversion into JSON format? Considering HTML does not have built-in Array support, what alternative method should be used? In each row, there are 2 text fields and 1 select dropdow ...

Utilizing XPath with Selenium in VBA

In my search for a node based on text located within a child or grandchild node of its immediate sibling, I came across the following HTML structure: <div> <div class="searchedDivClass" id="DynamicId1"> </div> <div class=" ...

What could be causing my jQuery to only toggle the first arrow in my HTML?

I am facing an issue with a series of divs generated from data, each containing an arrow that should toggle an expandable section. Strangely, only the first div is functioning properly: toggling the arrow icon and revealing the content upon click. When th ...

The text is not rendering properly, with some characters being replaced by different ones

RESOLUTION: To fix the issue, eliminate font-family, font-size, and color properties from the parent div. UPDATE: The problem only occurs when I press CTRL + F5. UPDATE 2: After investigating, I found that the culprit is .site-footer with a position:abso ...

Interpreting HTML using a PHP script and running PHP commands embedded in the file

Does anyone know how to execute PHP code within an HTML file that is being opened inside a PHP file? Here's the scenario: I have an HTML file structured like this: <html> <head> <title></title> </head> ...

Can anyone assist me with this HTML/jQuery code?

Despite my efforts, I've been unable to achieve success. The challenge I'm facing is with duplicating controls for adding images. I have a button and a div where the user can choose an image by clicking the button. The selected image appears in ...

using javascript to target a specific css selector attribute

I have a CSS file with the following code: .datagrid table tbody td { color: #00496B; border-left: 1px solid #E1EEF4; font-size: 16px ;font-weight: normal; } Is there a way to use JavaScript to dynamically change the font size? The code below worked ...

Sharing Variables with $(document).ready

I need help understanding why this code is not functioning and how I can fix it. Despite my efforts to use namespaces and IIFEs, I am still unable to make it work. $(document).ready(function() { alert (hi); }); $(document).ready(function() { var hi = ...

Limit a div to only accept a specific stylesheet

Currently, I am immersed in a project that involves HTML5, MVC 4, CSS 3, JQuery, and LINQ. We have meticulously designed styles for various ui, li, and other html controls within the project. However, I now face the challenge of integrating a JQ Grid (htt ...

Trouble with CSS Vertical Alignment: Solutions to Fix it

Link to a JSFiddle for reference: http://jsfiddle.net/STmwz/4/ Initially, there is only the top div displayed. Upon clicking the edit button, the JavaScript code replaces the top div with the bottom div. However, during this transition, there is a slight ...

Is it advisable to incorporate Material-UI into a React project?

When it comes to designing a login page in react, I stumbled upon material-ui. The real question is, should we utilize Material-UI for this purpose? Furthermore, how can we manage styles in a separate file in the given examples? It seems logical to place t ...

Automate tasks without the need for a traditional form, simply using a text box and a

I've exhausted my search efforts on Google, looking for answers to any question relating to my issue. The webpage I am attempting to submit resembles this setup: there is no form present and the objects are not organized within a form structure. While ...

When the onLeave event of fullPage.js is activated

I am struggling to implement two CSS events when transitioning between sections on a fullPage.js application. To see my current progress, you can view the following fiddle: http://jsfiddle.net/pingo_/67oe1jvn/2/ My objectives are as follows: To modify t ...