Generating a borderless table using HTML and CSS on the fly

Currently, I am dynamically creating a table that will remain the same size. However, to keep my code neat and organized, I prefer not to create it statically. I am familiar with how to achieve this using a static table.

The table I want to create should look similar to this: table

In my code, I have defined a table class called "tableClass" and a td class named "activeCell."

Here are some methods I've tried:

  • I attempted adding an id to each td and then creating custom CSS for each id.
  • I used ".activeCell:nth-child()" but found that it applied the style to the entire column rather than just the individual cell (td).
  • I also tried assigning an id to each cell and then using ".activeCell#id," but saw no visible change in styling.
  • Additionally, I tested using "td:nth-child()" which did not produce any visible changes.

I am working with Angular as well. If there is a more convenient or simpler way to accomplish this task, I am open to using mat-table or Bootstrap (though I am unsure of how to style the table using those frameworks).

Your assistance would be greatly appreciated.

Below is a snippet of my HTML code:

<table class="miniGame">
    <tr>
        <td class="activeCell" *ngFor='let cell of grid | slice:0:3; let i=index' (click)='markCell(cell.id)'
            id={{cell.id}}
            [ngClass]="{inactive: !cell.isActive}">
            {{ cell.value }} A
        </td>
    </tr>
    <tr>
        <td class="activeCell" *ngFor='let cell of grid | slice:3:6; let i=index' (click)='markCell(cell.id)'
            [ngClass]="{inactive: !cell.isActive}">
            {{ cell.value }} B</td>
    </tr>
    <tr>
        <td class="activeCell" *ngFor='let cell of grid | slice:6:9; let i=index' (click)='markCell(cell.id)'
            [ngClass]="{inactive: !cell.isActive}">
            {{ cell.value }} C </td>
    </tr>
</table>

And here is a snippet of my CSS:

.activeCell{
    width: 100px;
    height: 100px;
    cursor: pointer;
    border-top: 2px solid black;
    border-right: 2px solid black;
}
.activeCell:hover{
    background: rgb(79, 77, 223)
}
.miniGame{
    border-collapse: collapse;
}

Answer №1

:first-child and :last-child can be used to achieve this effect:

table{ 
  border-collapse: collapse; 
}

/* styling the table cells instead of the whole table: */
td {border: 2px solid; width: 30px; height:30px;}

/* removing borders from top and bottom rows: */
tr:first-child td {border-top: none}
tr:last-child td {border-bottom: none}

/* excluding borders from first and last columns: */
td:first-child {border-left: none}
td:last-child {border-right: none}
<table>
  <tr>
    <td></td><td></td><td></td>
  </tr>
  <tr>
    <td></td><td></td><td></td>
  </tr>
  <tr>
    <td></td><td></td><td></td>
  </tr>
</table>

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

Transforming text into numbers from JSON response with *ngFor in Angular 6

I'm currently attempting to convert certain strings from a JSON response into numbers. For instance, I need to change the zipcode value from "92998-3874" to 92998-3874. While doing this, I came across a helpful resource on Stack Overflow. However, I s ...

Encountering Axios CanceledError while attempting to forward a POST request using Axios

While attempting to relay a POST request from an express backend to another backend using axios, I encountered an axios error stating "CanceledError: Request stream has been aborted". Interestingly, this issue does not arise when dealing with GET requests. ...

Angular 12: Ensure completion of all data fetching operations (using forkJoin) prior to proceeding

Within my ngOnInit function, I am looking for a way to ensure that all requests made by fetchLists are completed before moving forward: ngOnInit(): void { this.fetchLists(); this.route.params.subscribe(params => { this.doSomethingWit ...

Advanced Angular2 Services Expansion

I'm looking to enhance an existing angular service (for example, Http). Requirements: The extension of the service should be done through angular's dependency injection It should be possible to extend the service multiple times using a pattern ...

The attempt to compress the code in the file from './node_modules/num2persian' using num2persian was unsuccessful

I have been using the num2persian library to convert numbers into Persian characters. However, whenever I run the command npm run build, I encounter the following error: An error occurred while trying to minimize the code in this file: ./node_modules/num ...

Express.js continues to retrieve outdated query results that have already been removed from the database

I am experiencing a strange issue with my PostgreSQL and Express.js setup. Despite updating my database with new entries and deleting old ones, it seems to only display the old data that was deleted days ago. It's almost as if it's stuck in some ...

Using JavaScript to transmit information from a view to a controller in CodeIgniter

I am looking to pass multiple values from the view to the controller using JavaScript based on the dropdown selection. Below are my code snippets: <select name="class" id="class"> <option selected value='-1'>--Select Class--</o ...

Encountering some difficulties while setting up my development tool (specifically webpack)

I have embarked on a journey to learn modern JavaScript with the help of Webpack and Babel. As a beginner in this field, my instructor is guiding me through the principles of modern JavaScript by building an app called Forkify - a recipe application. While ...

Viewing HTML files remotely using Kendo UI Mobile

I developed a sample hybrid app using the Telerik App Builder CLI. The project features an initial home screen loaded from a COMPONENTS folder within the project. Within the Components folder, there is a Home folder containing an index.js and view.html fil ...

What is the process for utilizing AngularJS's multiple $http calls to retrieve data from a single PHP file?

I'm currently experimenting with multiple AngularJS ajax calls to a single php file in order to retrieve different json data based on the request. Below is the code snippet I am working with: var myApp = angular.module('myApp', []); myApp ...

Children of unrelated parents may have similar height levels

Is there a way to make two unrelated divs have the same height using jQuery? Most solutions I found are for children of the same parent, but in this case, I need to equalize the heights of Parent B's child to Parent A's child. The code snippet be ...

Delete a specific element based on its class by utilizing the parent() method

As I modify a jQuery validator, it adds a div to the parent element when an error occurs. My goal is to remove this inserted div with a specific class name from the parent. $(element).parent().remove('.removeThis'); Although I expected the code ...

Google Maps Circle Radius Functionality Malfunctioning

I've been trying to implement a map scaling feature using a slider in my code but I'm having trouble getting it to work. While the map is displaying correctly, the radius won't update as intended. Any assistance with this would be greatly ap ...

What is the proper method for writing a service and adding an image in Angular 2?

I currently have a model: export class Photo{ constructor( public users_id: number, public photo: Blob ) { } } Additionally, there is a service: import {Injectable} from '@angular/core'; import {Photo} from '../../ ...

Two identical Vue component instances

Is there a way to duplicate a Vue component instance after mounting it with new DOM? I am currently working on coding a template builder and I need to clone some blocks. Similar to the duplicate feature on this website ...

Create a prototype class in NuxtJS Vue

What is the correct way to set a class to prototype in Vue NuxtJS? I have created a plugin Here is my nuxt.config.js file: plugins: [ { src: "~/plugins/global.js" }, ], The global.js file contains: import Vue from "vue"; import CustomStore from "dev ...

Is there a way to determine the dimensions of an element that is set to "display: none"?

Is it possible to retrieve the dimensions of child elements inside a div that has been hidden with CSS property display: none? If so, how can this be achieved? Check out the Fiddle Demo here var o = document.getElementById('output&apos ...

Content Pagination with Bootstrap

I need some guidance on how to effectively utilize the bootstrap pagination plugin for displaying content. The current code simply shows "page" followed by the page number. Can someone advise me on how to include text within paragraphs? Please refer to t ...

Having issues with the jquery append function not cooperating with the <ngx dropzone> component

I am trying to use the jQuery .append function, but it doesn't seem to be working for me. Is there a solution to this issue? <ngx-dropzone [showPreviews]="true" #dropzone [showPreviews]="true" [preserveFiles]="false" [accept]="'image/png, ...

How can one variable hold multiple values simultaneously?

Here is some AngularJS code that may be new to you: var deferred = $q.defer(), nextTransClass, prevTransClass; Can anyone explain the purpose of this variable assignment? It's not something I've encountered before. ...