Using Bootstrap cdn in my React JS project caused conflicts with my custom CSS styles

I recently created a webpage in ReactJS and styled it using CSS. In order to enhance the styling of one component, I integrated Bootstrap by adding the latest CDN link to my "index.html" file. However, I noticed that the Bootstrap styles were overriding some of my custom CSS styles. My project consists of separate CSS and JS files for each component. Can you recommend a solution for me to include the Bootstrap link in a way that it doesn't interfere with my custom styles? Thank you.

Answer №1

It seems like there is an issue with the css include order causing a strange smell. Take a look at it in your browser to verify. To fix this problem, consider trying one of the following solutions:

  1. Ensure that bootstrap css is the very first link in the head section (after meta).
  2. Alternatively, try importing your css using import in your index.js file.

The second option should resemble the following structure:

import "https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css";
import "./styles.css";

Answer №2

To easily customize your CSS, simply link your custom CSS file directly after the bootstrap.css file and make your changes in the custom.css file.

Avoid using descendant selectors, IDs, and '!important' notation together to override styles as it goes against CSS best practices. Reserve these techniques for when absolutely necessary.

Follow this straightforward method by checking out these helpful articles. I hope you find them useful:

Override Bootstrap CSS styles

CSS Overrides

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

I'm looking for a way to change the color of a specific div out of the 3 I have, but I don't want to use

<div></div> <div> paragraph</div> <div>paragraph1</div> Looking for a solution to change the background color of an empty div using only CSS, without making any changes to the HTML. Can anyone provide assistance with ...

Formatting that differs based on whether the content appears on the left

I'm in search of a solution to align specific items to the left on left-hand pages and to the right on right-hand pages. I have come across @page :left/:right, but it seems to only affect the page layout and margins, not the actual content on the page ...

Discover the secrets to achieving complete customization of your data table's appearance using the DevExtreme React Grid in conjunction with material-ui

I am facing difficulties in styling the DevExtreme React Grid, which I found from their documentation here. Here is the sample code that I copied from another repository. I have a few questions: How can I have complete control over the styling? I noti ...

JavaScript Event Listener not Working Properly

I've been attempting to implement a feature on my website where the header hides when scrolling down and re-appears when scrolling up. However, I'm struggling to make use of the code snippet below to achieve this functionality. Despite my thoroug ...

The anticipated reply was supposed to consist of an array, however it ended up being an

I'm brand new to Angular and I've been searching for a solution to my issue with no luck. My app is supposed to retrieve data from a MongoDB database and display it to the user. However, I keep getting this error message: Error: [$resource:bad ...

Tips for showcasing checkbox options on an HTML page (utilizing ejs) following the retrieval of information from MongoDB and making it editable for the User

Currently, I store data in mongo for a multiple-choice question and indicate the correct answers. In mongo, I save them like this: question.options.option1.check = "on" for the correct answers. When I navigate to the "edit" page, I retrieve the specific ...

Utilizing AJAX within a Rails application to dynamically alter a database field without the need for a traditional form

I am facing a scenario where I have implemented a table with certain rows structured as follows: <div class="row chord-table-row" id= <%= "chord-#{chord.id}" %>> <div class="small-1 columns"><%= chord.id %></div> < ...

Utilizing AngularJs and Materialize.css to create numerous dropdown menus

I am encountering a troublesome issue that I just can't seem to resolve. My current setup involves using AngularJs to showcase a set of cards, each equipped with its own dropdown menu. Here's the snippet of code in question: <div ng-repeat=&q ...

Verifying the execute boolean status or utilizing try/catch with PDO

Apologies for the subpar title. My project heavily relies on AJAX, with most responses returning either 'error' or 'success' messages in an array. In my Javascript code, I display these messages in a custom notification bar. I'm u ...

A program that saves numerous data from a JSON dictionary into an array

I have a large collection of dictionaries in JSON format obtained through an API request totaling over 1000. How can I develop a script that can loop through all the dictionaries and extract the values from one specific key-value pair? For instance: "te ...

Tips for wrapping text to fit the width of a column

Hello, I have a table with varying column widths as shown below ${"#goldBarList"} table tr td:first-child{width:5%;} ${"#goldBarList"} table tr td:first-child+td{width:5%;} ${"#goldBarList"} table tr td:first-child+td+td{width:6%;} ${"#goldBarList"} table ...

Whenever my NodeJs encounters an unhandledPromise, it throws an error

https://i.sstatic.net/w6sa9.png exports.createNewTour = async (request, response) => { try { const newlyCreatedTour = await Tour.create(request.body); res.status(201).json({ statusCode: "success", details: { tours ...

Leveraging conditional statements for dynamically computed Vue properties

In the Vue site I'm working on, there is a functional button that changes its state when clicked (from "pause" to "resume" and also changes colors). The button functionality itself works perfectly, but I am facing an issue in aligning it with another ...

Override the default Bootstrap 5 styling for nav-links

I recently encountered a problem while trying to customize the appearance of the nav-link elements in my Bootstrap 5 navbar. I initially thought I could simply override the existing styles by targeting the class in my CSS. However, my attempts were unsucce ...

Identifying Changes with jQuery Event Listeners

I am trying to run some javascript code that is in the "onchange" attribute of an HTML element. For example: <input id="el" type="text" onchange="alert('test');" value="" /> Instead of using the onchange attribute, I want to trigger the e ...

What could be the reason why the @media print selector is not showing the correct format when I try to print?

When I click the print button, the text is supposed to display in four columns in the print dialog, but it appears as paragraphs instead. This is my script code where there is a click event for the print button. When I click on it, the print dialog pop ...

Divide and conquer- Lighttpd's mod_wstunnel combines separate messages by using UNIX socket communication to the backend server

In my experience with lighttpd's mod_wstunnel, I have encountered a peculiar issue. When I send two messages in quick succession from the backend using a UNIX socket to communicate between lighttpd and the backend, I noticed that lighttpd logs show th ...

Tips for adding a bounding box to an image received from the server

I've got a python server that is returning a collection of bounding boxes post OCR processing (using Tesseract or similar). "bbox": [{ "x1": 223, "y1": 426, "x2": 1550, &q ...

Initiating Internet Explorer using the APTool application for Selenium automation

Have you ever encountered a situation where you needed to open Internet Explorer from the start menu with the right-click option open with *apptool and then navigate to a specific webpage? I wonder, is it possible to automate this process using Selenium W ...

Firefox doesn't seem to support keyframes animation

I implemented keyframes to create a pulsating effect on text every 15 seconds. This effect works in Chrome but not in Firefox. I'm unsure how to introduce a 15-second delay between each pulse, so I experimented with using more percentages; however, I ...