Discover the secret to customizing numerous bootstrap cards with CSS - identify the mistake

I have some Bootstrap cards that I want to customize with CSS by overriding the default styles.

Card code

<div class="card" style="width: 18rem;">
  <img src="https://cdn.ymaws.com/cilip.site-ym.com/resource/resmgr/cilip/information_professional_and_news/non_infopro_news/2020_03_coronavirus/coronavirus_header.png" class="card-img-top" alt="...">
  <div class="card-body">
    <h5 class="card-title">Card title</h5>
    <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
    <a href="#" class="btn btn-primary">Go somewhere</a>
  </div>
</div>

CSS added in the head tags

<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">

<style>
  .card{
body {
  color: blue;
}
h1 {
  color: green;
}
p{
  color: red;
}

}
  </style>
</head>

In the following snippet

<style>
      .card{

I am attempting to target the Bootstrap class "card" and modify its styling.

If someone could help me identify my error and provide a beginner-friendly solution with explanation, I would appreciate it.

Goal: My aim is to apply the provided CSS to style the card. Specifically, I want headings to be green, paragraphs to be red, and the body of the card to be blue. However, the styling in the head section does not seem to affect the card.

What I've tried:

I also attempted to target each element separately as recommended

<style>

.card-body{background-color: blue;}
.card-body{h1: green;}
.card-body{p: red;}
  
</style>

In this case, the first style (blue) worked but did not change the h1 and p elements as intended.

Answer №1

Each element must be coded individually, like this

.card-body{background-color: blue;}

Answer №2

In order to overwrite a previous style, it is necessary to apply the !important declaration.

As an illustration:

p {
  font-size: 16px !important;
}

Answer №3

To modify your CSS code, follow these steps:

<style>
.card-body { color: blue; }
.card-body h1 { color: green; }
.card-body p { color: red; }  
</style>

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

Are you accessing the site on a variety of gadgets?

I am currently working on a website with the goal of making it responsive. So far, it looks great on desktops and mobile phones like the iPhone and Galaxy S4. However, I am encountering difficulties in making the website look like it is on a mobile phone w ...

Is it possible to maintain tab focus instead of visual focus when navigating past the skip navigation menu for improved accessibility?

My website features an accessibility skip navigation menu that utilizes named anchors to navigate to different content areas. These content areas, including the top menu, left menu, main body content, and footer menus, contain links within them. When I u ...

Hidden footer error has been resolved despite background visibility

Greetings! This marks my debut post on this platform. I've encountered a minor setback with the current website project I am working on. As I have implemented a CSS parallax header, I aimed to create a distinctive footer as well. The concept was to ...

WordPress website displaying two identical logos

Despite not making any core changes, this morning while performing some W3 validation, the logo inexplicably began duplicating at random and I am unable to locate the error. You can view the issue here: I have reverted the header.php file back to its ori ...

The hidden inner div fades away within the confines of a trapezoid-shaped container

I've been attempting to position a div within another trapezoid-shaped div. However, the inner div remains invisible no matter what I try. Z-indexes have also been tested. .trapezoid { border-color: transparent transparent rgba(255,0,0, ...

JS has the ability to determine the media style of a DOM element

I am trying to retrieve the CSS display property of a DOM element. Normally, I would use something like document.getElementById('hello-world').style.display. However, when the style is set using a CSS @media Rule, I do not see any change in this ...

Is it possible to use multiple versions of Bootstrap on a single webpage?

My goal is to incorporate Bootstrap into a page that already has both an old version (version 3) and a new version (version 4) of Bootstrap, but I am facing JavaScript conflicts. I am trying to embed it on a third-party site over which I have no control. ...

How can CSS height/width be verified according to set guidelines?

I am currently in the process of developing an ASP.NET control that generates <object> and <embed> tags. In order to ensure compatibility, I intend to add "Height" and "Width" properties to the control as both tags require these attributes. Add ...

Styling of CSS class not applied when displayed following an <hr> element

I am facing an issue with styling links on my webpage. I have a list of links to different websites, each followed by a brief description. To ensure the link text is slightly larger than the description, I created a CSS class called a.link with a font-size ...

Frosted and see-through circular background effect triggered by mouse movement

I've been attempting to duplicate the mesmerizing effect showcased on this webpage: (give it a try by moving your mouse), but I'm baffled by how they managed to achieve it? My attempts at experimenting with a JSFiddle can be found here: http:// ...

Dynamic CSS view size parameter

Currently, I am studying how to create responsive designs using CSS. I decided to test out some example code provided on the w3schools website (https://www.w3schools.com/css/tryit.asp?filename=tryresponsive_webpage). However, I encountered an issue where ...

Is it possible to create a similar design that is also responsive?

I've been struggling to create a header for a website project I'm working on. My goal is to design something like the image below: https://i.sstatic.net/szQGf.jpg The biggest challenge I'm facing is making this design responsive. The point ...

Ensure that divs remain in a static position within the dialog box

Within the jQueryUI dialog, I have gray boxes at the top and bottom of the visible area represented by the .nav elements. I want these gray boxes to stay fixed in their position even when scrolling within the dialog. Despite setting position: absolute, the ...

Unable to navigate through the menu - the content that is "hidden" behind the menu will scroll

Recently, I put together a compact menu using tailwindcss which is functioning well. However, there seems to be an issue when this menu is viewed on mobile devices, as the user ends up scrolling the content underneath the menu instead of the menu itself. T ...

What is the best way to dynamically adjust row sizes in react-bootstrap?

I have successfully created a grid of cards in groups of three using react-bootstrap. However, I am facing an issue where if one card's height is longer than the others, it creates unnecessary space and disrupts the layout of the entire row. You can s ...

Issues arise with jQuery onclick event functionality when the DOM structure is altered

I'm struggling to grasp the concept of jQuery (v1.11) when it comes to events and how DOM interaction impacts those events. The scenario: I am creating a grid of inline-blocks with the class "letter" and listening for clicks: $('.letter).on(&a ...

After sending an HTML Gmail using Nodemailer, some rules may be missing from the CSS

I am attempting to send HTML content via Nodemailer to my Gmail account. Initially, I sent the email as plain text to ensure everything was working properly. const email = { from: emailAddress, to: sendTo, subject: ...

Centering the contents of the grid

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=de ...

Modify the input value when using the get_search_form() function in Wordpress

After experimenting with the latest get_search_form() function in WordPress, I've encountered an issue where I can't figure out how to remove the text label from the search submit button. Does anyone have any suggestions or solutions for this pr ...

Utilize LESS Bootstrap as a guide for incorporating content

I have been struggling to properly integrate Bootstrap into my LESS file. Currently, I am adding Bootstrap to my project using NPM. If I simply use the following import statement in my LESS file: @import (reference) 'node_modules/bootstrap/less/boot ...