Customize border color for a single cell in a table using Bootstrap 4

I'm facing an issue where I'm trying to apply a red border color to a specific cell, but it's not appearing on the top and left sides of the cell. It seems like the border color of other cells is taking precedence over the one I'm trying to apply.

Here's the CSS code I'm using:

.border-red
{
 border:red solid 1px !important;
}

Any suggestions on how to resolve this problem would be greatly appreciated. Thank you in advance.

Answer №1

To fix the issue, modify the CSS property border-collapse: collapse; to border-collapse: separate; (which originates from the Bootstrap .table class) and include border-spacing: 0; if you wish to remove the space between cells.

table.table {
      border-collapse: separate;
      border-spacing: 0;
}

.border-red
{
 border:red solid 1px !important;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet"/>
<html>
<body>
<div class="col-6">
<table class="table table-sm table-bordered">
<tbody>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>Test User 1</td><link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet"/>
<html>
<body>
<div class="col-6">
<table class="table table-sm table-bordered">
<tbody>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>Test User 1</td>
<td>10</td>
</tr>
<tr>
<td>Test User 2</td>
<td class="border-red">90</td>
</tr>
<tr>
<td>Test User 3</td>
<td>20</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
<td>10</td>
</tr>
<tr>
<td>Test User 2</td>
<td class="border-red">90</td>
</tr>
<tr>
<td>Test User 3</td>
<td>20</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>

Answer №2

To ensure proper display, simply add the style display:block; to your code snippet.

.border-red
    {
     border:red solid 1px !important;
        display: block;
    }

Answer №3

Swap out the border-collapse: collapse; class for border-collapse: separate;

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

Trouble Ensues as CSS Div Refuses to Center

I'm in the process of creating a practice website to improve my HTML and CSS skills, but I'm having trouble centering a specific div. I've attempted to use margin: 0 auto, but it doesn't seem to affect the positioning of the div at all. ...

Guide to counting the number of image tags within a parent div and selectively removing them starting from a specific position

My dynamic image tag <img> is generated inside a div from the database using fetching. Here is how my HTML looks: <div class='forimgbox'> <p class='palheading'>Pals</p> <img src='userpic/2232323.p ...

When running the function `.find('li')` on a `bs4.element.Tag` object, it returns None despite the presence of the <li> tag within the soup

As I work on parsing the content of a URL using BeautifulSoup after making a request with `requests.get()` (not displayed in the code), I am using the parser ""html.parser"". Below is a snippet from a larger script: print(f"subheading : {sub ...

The issue of a background image not appearing on Chrome and Firefox has been identified

I am experiencing an issue where a background image is not showing up on Chrome or Firefox, but it displays properly on other browsers. The problem occurs with relative and hard links Substituting the image file works, but the video disappears Adblock is ...

How can I adjust the flex spacing based on the width of the window?

My figures are evenly spaced using flex spacing, but when I resize the window, they extend beyond the parent section. Here is the HTML code snippet: <section class="features"> <figure> <img src="Images/Vanilla-Cup ...

Looking to showcase your logo prominently at the center of the page, flanked by two elegant

Is it possible to create a grid-like structure with dimensions 5.5-1-5.5? I would like to center a logo on the page with two lines on the left and right. (Please excuse my limited English skills) https://i.sstatic.net/cgjfS.png ...

Updating to version 4.1.0 resulted in Symfony and bootstrap layout being disregarded

I'm currently using Symfony 4 along with Bootstrap 4 and have implemented a layout named bootstrap_4_layout.html.twig. After upgrading Symfony from version 4.0 to 4.1.0, I noticed that some parts of the layout are not displaying correctly. How can I ...

Ways to convert a PHP script to utilize PDO

Previously, a query was used to retrieve website settings stored in the database by an administrator, such as MyCompanyName or Copyright text. These settings were added in the site's backend by the admin. <?php error_reporting (E_ALL ^ E_NOTICE) ...

Is it feasible to utilize a Heroku Node server solely for serving basic HTML pages?

Is there a way to simply upload multiple HTML (or any) files and access them via URL without having to define routes, set up static files, etc.? I am using a NodeJS/ExpressJS app and would like to serve certain files and folders as regular HTML pages. ...

Ways to display or conceal various divs by employing an if/else statement?

I am aiming to conditionally display various divs based on certain criteria: Show the "x" div if it's not already visible Display the "y" div only if the "x" div is already being displayed Show the "z" div only if both the "x" and "y" divs are alrea ...

Using JavaScript to modify the -webkit-animation-play-state

Hello, I'm currently facing a challenge in changing my css3 -webkit-animation-play-state property from paused to running upon clicking on another div. Does anyone have any suggestions on how I can achieve this? I believe JavaScript might be the way to ...

Insert the characteristics of the object into the header of the table, and populate the rows of the table

I have created an HTML table that displays specific object properties when the mouse hovers over a designated object. For example, hovering over the dog object will display the dog's name. I want to expand this functionality to also show the cat' ...

How to Implement Loading Image with CSS

I have customized the CSS code below to style a div element that showcases a responsive image. .my-img-container { position: relative; &:before { display: block; content: " "; background: url("https://lorempixel.com/300/160/") ...

What value is used as the default for justify content?

MDN states that the default value of justify-content is normal, even though it's not listed in the accepted values. What exactly does a normal value mean? normal This means that items are packed in their default position as if no justify-cont ...

Changing the text color of an active button in Bootstrap

Hello everyone, I've been struggling to find a solution to my issue and I could really use some help. The problem I'm facing is changing the text color of the active button in Bootstrap. Specifically, after clicking on a button, I want it to tra ...

Ways to incorporate padding into md-card using Angular 2 material

Need assistance with adding padding to md-card in angular2 material. I am using md-card to display my product list but struggling to add padding on them. Here's what I have tried: product.component.html : <p> Product List </p> <div ...

The dropdown within the modal is proving elusive for Selenium to locate

I am attempting to choose a value from the dropdown menu labeled 'ddl_settpymtaction' using Selenium, but unfortunately it seems to be unable to locate it within the modal where it is located. CSS: https://i.stack.imgur.com/3YWQu.png Selenium ...

How can JavaScript be used to create a unique signup and login process on

I am struggling with storing sign up and login details in JavaScript. In my previous project, I used PHP and a database to handle this information, so transitioning to JavaScript has been challenging. Here is an example of the sign-up HTML code: <!DOC ...

Issue with displaying Django Bootstrapv5 component in carousel item

I am struggling to display at least 5 cards in each carousel-item, but currently it only shows one card per item. Can you help me figure out what needs to be done? {% for knowledge in knowledges %} <div class="carous ...

Nested tabs in Bootstrap 3

I am currently developing an application that contains a lot of content organized in nested tabs. Everything seems to be working fine except for one issue where clicking on a nested tab does not display the content. <ul class="nav nav-tabs"> <l ...