Ways to change the border color of Bootstrap cards

While working on my webpage, I utilized bootstrap cards to maintain a clean and organized layout. By default, bootstrap cards are white in color. Unlike the navbar, where you can easily set color options like navbar-dark, changing the color of the cards required manual adjustment. Everything seemed to be going smoothly, but there was a small issue that bothered me - the border between the header and the title. Due to the black border against the black card color I chose, it became almost invisible.

ScreenShot of my Issue: https://ibb.co/8MqtRJP

PS: If you can't see the border on the bootstrap card try looking again, because it is kind of hard to see at first

My Code:

<div class="card" style="width: 800px; border-radius: 23px; background-color: rgb(35, 33, 33); color: white;">
    <h5 class="card-header" style="color: white" >Time Managing</h5>
    <div class="card-body" style="color: white" >
      <h5 class="card-title">Prioritization</h5>
      <p class="card-text">Additional content.</p>
      <a href="#" class="btn btn-primary">Learn More</a>
    </div>
  </div>

I tried using the class="card" and giving it a style of

.card {
  border: color: white;
}

I expected the border to change to white as it is usually done with the border property, but that approach did not work.

Does anyone have any suggestions or solutions to resolve this issue?

Answer №1

When working with the card-header in Bootstrap, you have the option to use predefined classes like border-bottom border-light, or you can define a custom class or inline style with border-bottom: 1px solid #fff.

To learn more about border classes in Bootstrap, you can refer to the official documentation.

If you want more information on using inline styles for borders, check out the MDN documentation.

Here is an example:

main {
background-color: #333;
color: #fff;
padding: 20px;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="02606d6d76717670637242372c302c31">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<main>
<p>With Bootstrap class 👇</p>
<div class="card" style="width: 800px; border-radius: 23px; background-color: rgb(35, 33, 33); color: white;">
  <h5 class="card-header border-bottom border-light" style="color: white">Time Managing</h5>
  <div class="card-body" style="color: white">
    <h5 class="card-title">Prioritization</h5>
    <p class="card-text">Additional content.</p>
    <a href="#" class="btn btn-primary">Learn More</a>
  </div>
</div>
<br/>
<p>With inline style 👇</p>
<div class="card" style="width: 800px; border-radius: 23px; background-color: rgb(35, 33, 33); color: white;">
  <h5 class="card-header" style="border-bottom: 1px solid #fff; color: white">Time Managing</h5>
  <div class="card-body" style="color: white">
    <h5 class="card-title">Prioritization</h5>
    <p class="card-text">Additional content.</p>
    <a href="#" class="btn btn-primary">Learn More</a>
  </div>
</div>
</main>

Answer №2

Hey there, it seems like the syntax in your css is a bit off. Here's a revised version:

.card {
  border-color: white;
}

Make sure that each css property and value pair is on its own line with a semicolon at the end, like

<css-property>:<value>;
. In this case, you need to modify the border-color property to have a value of white.

Based on your comments on another answer, if you want to change the border at the bottom of the .card-header, you also need to set the same border-color value for the .card-header class. Make sure that the class you are modifying already has the necessary border properties, like width.

Using browser developer tools for debugging can be very helpful in situations like this. You can inspect and modify css styles directly in the browser to test how they will look and function. I often use this approach to verify styles before applying them to ensure they work correctly, especially when using frameworks like Bootstrap.

Answer №3

It is recommended to resolve this issue in version 5.3, however, for users on earlier versions, the following workaround can be used:

.card.text-bg-dark {
  --bs-card-border-color: #C3CBD2;
}

Assuming the class .text-bg-dark is utilized.

The default border color of the BS5 Card is #C3CBD2. The exact variable name escapes me at the moment.

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

Simple steps to add a click event listener to every element within a div

I need to assign a click handler to multiple elements and perform different actions based on which one is clicked. To illustrate, I can create an alert displaying the class of the button that was clicked. The elements I am working with have a similar str ...

The submission of FormData to the PHP server is causing an issue

I am having an issue with sending the formData to my PHP script using AJAX. Despite inspecting the elements, I can't find any errors in the process. Below is the structure of my form: The input values are sent to a JS file onclick event. <form c ...

Top tips for utilizing CSS in a web component library to support various themes

Our team is currently in the process of developing a comprehensive design system that will be utilized across multiple projects for two distinct products. Each product operates with its own unique brand styleguide which utilizes design tokens, such as: Th ...

Transform your ordinary HTML select into a stylish span with this custom CSS class

I need help making a select element appear like a span under certain conditions. The CSS class I currently have works with input boxes, but not with dropdowns. Is there any advice on how to style the select element to look like a span without actually repl ...

Grammarly is seamlessly inserting padding into my body element

After setting up my website on GitHub, I ran into an issue where the Grammarly Chrome extension was automatically adding a padding-top attribute to the body tag. <body data-new-gr-c-s-check-loaded="14.1028.0" data-gr-ext-installed="" ...

What is the best way to use JavaScript to fill in missing images with alternative HTML content?

As a provider of a service that helps users find the location of pictures, I face a challenge due to the fact that the pictures are stored on another internal site. Some users may not have access to this site as my service offers additional information. Th ...

I am encountering issues with setting a background image in Bootstrap 3.1.1 while trying to achieve a par

I'm struggling to add a background image to my bootstrap site. I'm attempting to create a parallax site using stellar.js, and while the site is functional with text on each slide and correct scrolling links, the images just won't load. Despi ...

Would it be possible to use a script to convert the y-axis values of the chart into Arabic numerals?

Currently, I am working on creating line and pie charts, but I need the Y-axis to display Arabic language. $('button').on('click', function(e) { $('#pie-chart3').empty(); var type = $(this).d ...

Implementing timeAgo with jQuery (or a similar tool) to display the elapsed time since a user (client) accesses or updates a webpage

https://i.sstatic.net/Y7bzO.png Currently, the timer displayed always shows the actual time instead of phrases like "about a minute ago" or "5 minutes ago". I have tried different solutions without success. //timeago by jQuery (function timeAgo(selector) ...

Check out this unexpected margin issue affecting the first element within the Container! Can you please provide an explanation for this anomaly?

Take a moment to check out this fiddle. In Container1 and Container2, the background color is set to #ccc, and h1 and .logo div have margins. While the left and right margins are working properly, the top and bottom margins are not functioning as expected. ...

Navigation bar collapse items are not properly aligned in the layout

My navbar collapse button is not aligning the items in the dropdown properly. I suspect it has to do with the way I have structured the divs. How can this issue be fixed? <nav class="navbar navbar-expand-md navbar-light mb-4 row"> <b ...

Can you help me create a CSS Toggle similar to this design?

I am currently working on a website and I need to create a FAQs page with a specific layout. When a user clicks on a question (Q), the answer (A) should open smoothly using jQuery animation. Only one question should be visible at a time. If a user clicks ...

When a key is pressed, apply a background color and fade out effect using JavaScript

Whenever the enter key is pressed, I want to make a red color appear briefly and then fade out quickly to create a blinking effect. I attempted adding a new class on Keypress that would transition the opacity to 0: function enterpressalert(e, text) { ...

Learn how to showcase a predetermined option in an HTML select element using Vue.js and Minimalect

I am currently utilizing Vue.js along with the Mininmalect HTML select plugin to showcase a list of countries by their names and values, where the value represents the 2 digit country code. Successfully, I have managed to implement the plugin for selectin ...

I am looking to initiate the animation by triggering the keyframe upon clicking a button

Is there a way to create an animation triggered by a button click instead of loading the page? Each table data cell has its own class with a unique keyframe defining the style changes over time. @-webkit-keyframes fadeIn { from { opacity:0; ...

Struggling to make JavaScript read JSON data from an HTML file

I am currently working on developing a word search game using django. One of the tasks I need to accomplish is checking whether the entered word exists in a dictionary. To achieve this, I have been converting a python dictionary into JSON format with json. ...

Positioning Data Labels Outside of Pie or Doughnut Charts in Chart.js

I am currently working on a large-scale project and I am in need of a way to position the labels outside of pie charts or doughnut charts. I came across a plugin called outerLabels on GitHub which seems to be the perfect solution for what I need, but I am ...

What is the best way to align an image to flex-end?

I recently started using React and ran into issues trying to align my image using CSS. Despite trying various methods like justifyContent, justifySelf, and floating right, I couldn't get the image to align on the right side of the screen without resor ...

What are some tips to speed up image loading times?

Is there a way to optimize the loading speed of these images? In my loop that displays profile pictures, the photos take between 1 to 2.5 seconds to load all at once. I attempted resizing with PHP, but it had minimal impact on the load time. How can I prel ...

Adding a variable to the .append function in HTML code

I am currently working on a way to include the current date and time when a user comments on a post in my forum. While I have successfully managed to upload the text inputted by the user into the comment section, I am now looking to also dynamically insert ...