I'm interested in creating a border between a CSS grid and designing a tic-tac-toe game board

I am currently working on a tic-tac-toe game and I need help creating a grid layout similar to this example.

.grid-holder {
    display: flex;
    justify-content: center;
    display: grid;
    grid-template-columns: 100px 100px 100px;
    grid-template-rows: 100px 100px 100px;
    column-gap: 5px;
    row-gap: 5px;

}

.grid {
    border: 2px solid red;
    text-align: center;
    padding: 20px;
    cursor: pointer;
}
<div class="grid-holder">
            <div class="grid">1</div>
            <div class="grid">2</div>
            <div class="grid">3</div>
            <div class="grid">4</div>
            <div class="grid">5</div>
            <div class="grid">6</div>
            <div class="grid">7</div>
            <div class="grid">8</div>
            <div class="grid">9</div>
</div>

Answer №1

To achieve this effect, you can utilize a single gradient. I have also simplified your code for easier adjustments. You can easily modify the gap and width to suit your needs:

.grid-holder {
  --g: 5px; /* adjust the gap */
  width: 300px; /* set the size */
  
  display: grid;
  aspect-ratio: 1;
  grid-template-columns: 1fr 1fr 1fr;
  margin: auto;
  gap: var(--g);
  background:
   conic-gradient(at calc(100% - var(--g)) calc(100% - var(--g)),#000 75%,#0000 0)
   0 0/calc((100% + var(--g))/3) calc((100% + var(--g))/3)
}

.grid {
  text-align: center;
  padding: 20px;
  cursor: pointer;
}
<div class="grid-holder">
  <div class="grid">1</div>
  <div class="grid">2</div>
  <div class="grid">3</div>
  <div class="grid">4</div>
  <div class="grid">5</div>
  <div class="grid">6</div>
  <div class="grid">7</div>
  <div class="grid">8</div>
  <div class="grid">9</div>
</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

Unable to locate the hidden element

Attempt to access the attribute of a shadow element resulted in encountering ElementNotVisibleException Element with CSS input[type='checkbox'] is not present on screen <checkbox _ngcontent-ebv-c14="" label="User Access" ng ...

HTML link with "mailto:" not opening in a new tab

Just posted for the first time! I'm attempting to create a mailto link using 'templated' JavaScript that pulls specific data from a JSON object: var menu = { "menu": [ { "title": "let's talk", "link": "mailto:<a href ...

How can I insert an image into a circular shape using HTML and CSS?

To achieve the desired effect, the image should be placed inside a circle with a white background. The image size should be smaller than the circle and centered within it. One possible way to accomplish this is: .icon i { color: #fff; width: 40px; ...

How to position a logo and search box in perfect alignment with CSS styling

I'm struggling to align a logo and a search box next to each other. The logo should be on the left and the search box on the right. header { background:#383838; height: 130px; border-top:10px solid #2C2 ...

Jquery click event only firing once

My challenge is drawing lines between two points, although I've managed to do it once. The issue arises when I try to repeat the process; nothing happens on the second click of a circle. Please note that this functionality only works in modern brow ...

Using Bootstrap's CSS classes, is it possible to modify the background color of a table cell?

I'm currently working with Bootstrap 5.0 CSS and attempting to create a table with customized cell colors using some of my own CSS styles. The color property seems to be working correctly, but I'm running into an issue with Bootstrap not recogniz ...

Connecting a remote CSS file to a React component: Step-by-step guide

I am currently working on a React component and I want to incorporate Google's MDL (Material Design Lite) into it. I followed the instructions provided on their website here, which state that I need to link the CSS from their server. However, when I a ...

Issues with Linear-Gradient functionality in NativeScript 8 on Android devices

I recently added a linear-gradient to an image in my NativeScript 8 app. Surprisingly, it seems to work perfectly on iOS, but I'm encountering some issues on Android. Despite trying solutions like using -webkit-linear-gradient(), the desired effect is ...

If the checkbox is selected, retrieve the product name and price and store them in an array

If the checkbox is checked, I want to retrieve the service name and its price in an array. To get the values of the selected items (i.e. service name and its price in an array), please explain how I can achieve this. $(document).on('click', &apos ...

Prevent a specific image from being impacted by CSS styling

I've implemented the following CSS on my website for image opacity: img { opacity:0.4; filter:alpha(opacity=40); } img:hover { opacity:1; filter:alpha(opacity=100); } Now, I am looking to exclude certain images from being affected by this ...

Tips for sending parameters to XSLT using a Javascript function

Despite my efforts to find a solution in various online posts, I haven't been able to resolve the issue. The challenge lies in my HTML file that includes a JavaScript function for parsing XML and rendering XSLT. I have multiple 'records' in ...

Tell me about the CSS ruby-align characteristic

While browsing online, I stumbled upon a reference to the ruby-align property that piqued my interest. After searching on w3schools for some examples, I was surprised to find no mention of it anywhere. I remembered that Ruby is a newer tag in HTML5 and de ...

Converting HTML table data into a JavaScript array

On my website, I have an HTML table that displays images in a carousel with their respective positions. The table utilizes the jQuery .sortable() function to allow users to rearrange the images by dragging and dropping. When an image is moved to the top of ...

Is there a way to ensure that my JavaScript code remains permanent?

Is there a way to have the website remember the user's theme preference between visits? For example, if they choose the dark theme, can it automatically be loaded the next time they access the site? This is my current javascript code for handling the ...

Chrome fails to apply CSS to Polymer 2 web component

The implementation of my web component in Polymer v2 is causing a styling issue specifically in Google Chrome. Despite including a CSS file that defines a style called n-action-button, the styling is not being applied to the content of the web component in ...

HTML5 video function is only supported in Internet Explorer, while other browsers display a black screen instead

My task involves creating an html5 application that can be accessed across all major browsers, including Chrome, Firefox, IE9, Safari, and Opera. One of the requirements is for the application to support video playback. I am utilizing the video tag and hav ...

How can you use ng-click to disable a div in AngularJS?

I'm looking to dynamically disable a div in AngularJS based on a certain condition. I know I can achieve this by adjusting the CSS (such as reducing contrast and color) but the div also has an ng-click property that I want to prevent from being trigge ...

Using regex for 'OR' conditions in regular expressions

I have been grappling with this issue for quite some time now. Can you offer any helpful hints or suggestions? When it comes to Outlook emails, we often see forwarded emails containing information within the email body like so: From: Jackson, Peter Sent: ...

Creating a Scrollable Content Container with Bootstrap's Flex Box

I am in the process of developing a typical application layout using Bootstrap 5 and flexbox. The layout consists of a top bar, bottom bar, and a content area that adjusts its size automatically. Within the content area, there is a side bar and a main cont ...

Show a div pulsating while simultaneously animating another div

After coming across this query on Stack Overflow about adding a class without jQuery if hovering over another class I encountered an issue with a div element that displays upon hovering over a span, which was functioning correctly. However, I also have a ...