Tips for designing a hexagonal chessboard using CSS

I am looking for help with a web development project where I want to create a CSS and HTML version of the hexagonal chess board shown here. My objective is to reproduce the grid structure of the chessboard while excluding the text that accompanies it.

Currently, I have made some progress with my code but I am facing challenges in completing the task. Here's what I have achieved so far:

.board{
    display: grid;
    grid-template-columns: repeat(11, 1fr);
    grid-template-rows: 1fr;
    overflow: hidden;
    width: 770px;
    height: 770px;
}

.board > .column {
    height: 100%;
    width: 100%;
    grid-template-columns: 1fr;
    grid-template-rows: repeat(11, 1fr);
}

.board > .column:nth-child(odd){
    transform: translateY(-35px) translateX(17.5px);
}

.board > .column div {
    width: auto;
    height: 70px;
    aspect-ratio: 1;
    clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
}

.board > .column div.field:nth-child(even) {
    background: rebeccapurple;
}

.board > .column div.field:nth-child(odd) {
    background: wheat;
}
<div class="board">
  <div class="column">
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div class="field"></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
...   </div> </div>

Answer №1

Executing your desired layout with HTML and CSS can be achieved through various methods. Although not the most elegant solution, it is functional.

The implementation I propose utilizes the display-flex property. One benefit of this strategy is the elimination of empty cells while maintaining correct order within the code structure.

    #board {
        display: flex;
        flex-direction: column;
        flex-wrap: wrap;
        align-content: flex-start;
        height: 40em;
    }
    
    .col {
        display: flex;
        flex-direction: column-reverse;
        width: 50px;
        margin: 14.5px;
    }
    
    /* Additional CSS rules for styling omitted for brevity */
<div id="board">
        <!-- Structure of the board's columns and cells -->
</div>

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

Structured chat interface with unchanging top and bottom sections

I'm currently trying to come up with a way to structure my chatbox so that it has a fixed header at the top and a fixed footer at the bottom, while allowing the chatbox body to scroll within those constraints. I've experimented with various appro ...

Is it possible to extract information from a website if the body or row does not contain any attributes?

As a beginner in the world of coding and this website, I kindly ask for some patience with me. I have successfully created code to scrape a particular website, extract data, and store it in a MySQL database. Everything is working smoothly. Now, my goal i ...

Seeking assistance with coding a beginner-level Google Chrome extension

Currently, I am working on developing a basic Google Chrome extension with 2 or 3 browser actions. I have been using Selenium IDE to capture the necessary steps in Firefox that I need for my project. However, I am unsure of how to translate these recorde ...

Displaying live updating information (Progress) on my website

I'm in the process of creating a web page that displays data from a datatable in a grid view. There's also a button labeled "Send To Excel." When a user clicks this button, the program begins generating a report by writing the datatable content i ...

The previous method of using `vue/compiler-sfc ::v-deep` as a combinator has been phased out. Instead, opt for the new syntax `:deep(<

When developing with Nuxt 2, I am encountering numerous [@vue/compiler-sfc] ::v-deep usage as a combinator has been deprecated. Use :deep(<inner-selector>) instead. errors when running npm run dev. After attempting to resolve the issue by changing a ...

What's the best way to keep the hover effect on my main tab while ensuring it doesn't impact the sub tabs?

I'm facing an issue with a hover effect on my "menu" tab that is also applying to the sub tabs within it. How can I prevent this from happening? Below is the code snippet causing the effect: `nav ul li:hover > a { color:#f9b97a; border-bottom:2p ...

Twitter Bootstrap utilizing a fixed width of 1024 pixels

For my project, I have been tasked with developing a website with a fixed width of 1024px. How can I adapt Twitter Bootstrap's 960px fixed width framework to accommodate for the 1024px width requirement? Are there any disadvantages to designing websi ...

When running `node compile.js`, no combined CSS file is being created

I have finally mastered the art of setting up and executing the "node compile.js" file in the claro theme folder to compile each *.less file into its corresponding *.css file. However, I noticed that the old claro.css file remains unchanged. Is this the in ...

Tips for Enhancing the Appearance of a List Input Box

While on my hunt for an auto-completing text field, I stumbled across lists. <label>Bad Habit <input list="badhabits" id="habits" name="habit"/> </label> <datalist id="badhabits"> <option value="alcoholics"> <option ...

Leveraging the jQuery click function to toggle elements on a webpage by referencing the current element with the keyword "this

I've been trying to implement a click event that toggles an element unrelated to the selected item's parent or child. I want to utilize "this" because there are multiple elements with the same class where I'd like to apply the same jQuery cl ...

The command 'source-highlight' is not a recognized internal or external command

Recently, I delved into the world of asciidoc and decided to create an example in Python. However, every time I attempt to display a code blog in HTML, I encounter an exception that says 'source-highlight' is not recognized as an internal or exte ...

Adjust the alignment of text to a precise vertical ratio of the image

Let's say I have this amazing logo with some artistic text in it that cannot be replicated using a downloaded WebFont In the image, the text baseline sits at 68% from the top and 32% from the bottom. Now I want to align text in an HTML document, whi ...

Obtaining user input from a content editable div in a React component

Get content from editable div const contentref=useRef() const handleclick=()=>{ setContent(contentref.current.value) console.log(contentref.current.value) } Element Properties <div name="textbox" ref ={contentref} cla ...

Shading half of the progress bar

I need to fill 50% of the progress bar with a red color. This is my attempt using HTML and CSS: .progress { width:100%; display: inline-block; height: 0.4615384615384615em; padding: 0.0769230769230769em; background: #fff; border: 1px solid # ...

The varying website layouts across different devices

I recently encountered an issue while working on my WordPress website. When I view the page, some features behave differently than expected. One example is a banner that moves in and out based on scroll position (using jQuery Waypoints). Interestingly, whe ...

What methods can I employ to utilize React/Node in retrieving project file data solely through the front end?

Overview Currently, I have developed a front-end only React web application by executing the command react-scripts build. To simplify routing files without manual intervention, I have integrated @react-file-based-routing/react-router-dom from npm. I am c ...

Ensure the header remains fixed when scrolling in an HTML page with Bootstrap

I created the following code. However, when I scroll down the table, the header disappears from view. I would like the header to always remain at the top, even when scrolling. Despite searching Google multiple times and trying various solutions, I have no ...

Selectize Fails to Populate Options Using Ajax

ExpressJS is the platform I am using to develop a management dashboard for a community project. Right now, my main concern is integrating a modal that allows users to add new games to a database. Although I am able to fetch data remotely, I am facing diffi ...

I'm having trouble showing the concealed list with JavaScript

I am new to javascript and facing a challenge. Whenever I update the list items in an HTML example from engineer, pilot, technician, if I select engineer, there should be an onchange event calling a function in JavaScript that shows a hidden select list co ...

Increase the size of the parent div as the height of the position:absolute child div grows

I am facing an issue with a parent div and its 2 child divs. <div id="parent"> <div class="child1 col-2"></div> <div class="child2 col-10"></div> </div> The child1 div has absolute positioning a ...