Import the global bootstrap settings into a ReactJS application

I have implemented react-universally as the boilerplate for my ReactJS application and I am using bootstrap 4 for styling. The main component, DemoApp, is defined as follows:

import 'normalize.css/normalize.css';

import React from 'react';
import Switch from 'react-router-dom/Switch';
import Route from 'react-router-dom/Route';
import Helmet from 'react-helmet';

import config from '../../utils/config';

import './globals.css';

import Error404 from './Error404';
import Header from './Header';

import AsyncHomeRoute from './AsyncHomeRoute';
import AsyncCounterRoute from './AsyncCounterRoute';
import AsyncAboutRoute from './AsyncAboutRoute';

/// Should change the language below according to user preference language

function DemoApp() {
return (
<div style={{ padding: '2rem' }}>
      <Helmet>
        <html lang="en" />
        <title>{config('htmlPage.defaultTitle')}</title>
        <meta name="application-name" content={config('htmlPage.defaultTitle')} />
        <meta name="description" content={config('htmlPage.description')} />
        <meta charSet="utf-8" />
        <meta httpEquiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <meta name="msapplication-TileColor" content="#2b2b2b" />
        <meta name="msapplication-TileImage" content="/favicons/mstile-144x144.png" />
        <meta name="theme-color" content="#2b2b2b" />
        
       {/* A great reference for favicons:
          https://github.com/audreyr/favicon-cheat-sheet
          It's a pain to manage/generate them. I run both these in order,
          and combine their results:
          http://realfavicongenerator.net/
          http://www.favicomatic.com/
        */}
        
       
       //remaining code removed for brevity
     
          
      <link rel="manifest" href="/manifest.json" />

        {/*
         NOTE: This is simply for quick and easy styling on the demo. Remove
          this and the related items from the Content Security Policy in the
          global config if you have no intention of using milligram.
        */}

      </Helmet>
      
     // remaining code removed for brevity   
   );
}

export default DemoApp;

Additionally, here is an excerpt from my global.css file which styles the entire application:

   html {
      box-sizing: border-box;
      font-family: 'Tangerine', serif !important;
      color: red;
    }
    
    ul {
      margin: 0;
      padding: 0;
      list-style-type: none;
    }

    ul li { display: inline; margin: 0 .5rem; }

The issue I am facing is that the font set (Tangerine) is not displaying as expected. It seems like it gets overridden by bootstrap's _reboot.css which sets all fonts to the bootstrap default.

I suspect that the problem arises from the import "./globals.css" command executing before loading bootstrap, causing bootstrap to overwrite my font settings with _reboot.

My question is, within the context of the DemoApp component approach, how can I reverse the order of loading so that globals.css is loaded after bootstrap completes its setup cycle, allowing my fonts to be utilized without interference?

If such inversion is not feasible, are there alternative solutions available to globally establish bootstrap variables in a ReactJS environment?

Your assistance is greatly appreciated.

Answer №1

Your globals.css file should take precedence over the global bootstrap.css, or at the very least, be applied after bootstrap.css has been loaded.

Since the file is considered global, you could include a link to it after loading bootstrap:

<link
  rel="stylesheet"
  href="/scripts/css/bootstrap.css"
/>
<link
  rel="stylesheet"
  href="/scripts/css/globals.css"
/>

Does this cover everything? Anything else I should consider?

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

Both the complete and success functions are not triggering simultaneously

When I try to use both success and complete together, it seems to not be working properly. If I omit dataType: "jsonp", then the success function works fine, but including it causes only the complete function to work. var reRank = false; function reAss ...

Retrieve database SQL information using JavaScript to display data

I'm struggling to push the value from a textbox to SQL and display it. Despite reading numerous topics, I still can't figure it out. My explanation skills are lacking, but hopefully you can understand what I'm trying to achieve, especially i ...

What is the Angular approach for configuring a form's encoding type to application/json?

I need to send form data using a POST request that triggers a download, making it impossible to use any Javascript requests. Therefore, calling a function with the $http service is not an option. Additionally, I require the corresponding backend route in ...

Why is TypeScript giving an error about an undefined object key, even though the key was assigned a value in the previous command?

type MaybeThereIsAValue = { [p: string]: string | undefined } ... let bar: MaybeThereIsAValue = {}; const key = "carpe"; bar[key] = "diem"; const why = bar[key]; // why is string | undefined I am confused as to why why is showing ...

Swaying while navigating through volumetric fixed step raymarching

Encountering a bug with my shaders while working on the vertex: varying vec3 worldPosition; varying vec3 viewDirection; void main() { gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); worldPosition = vec3(modelMatrix * vec4 ...

What is the best way to convert user input text into a JSON request?

How can I utilize the text entered inside an input field for a JSON request? $("document").ready(function() { var search = $('#input').val() var api = "https://en.wikipedia.org/w/api.php?callback=?&action=opensearch&format=json&a ...

What is the best way to create a responsive menu in code?

I am working on creating a responsive menu. Check out cuppcomputing For the desktop version, the whole panel will be displayed when it meets the max-width: 600px (tablet and mobile size). Initially, only the title is shown, and clicking on it will reveal ...

What is the process for inserting a hyperlink onto an image within a query slider?

I am experiencing difficulties when attempting to add hyperlinks to the images in my slider. I have come to understand that images cannot be clickable in jQuery sliders, so I have tried the following in the HTML: <div class="wrapper"> <div class= ...

Json with ExtJs columns data is fully populated

I am having trouble with displaying columns in my jsp which fetches json data. I am retrieving this json data in my javascript and using Ext.data.JsonStore but the columns are not showing up as expected. Here is the code for the store: store = new Ext.da ...

Passing a property to a click event handler in ES6 with React: What's the best approach?

Struggling with passing props to a click function in my React learning journey. I'm attempting to make a basic ES6 counter component that increases when a button is clicked. The click function I have so far is: click() { this.setState({ c ...

Developing Modules in NodeJS using Constructors or Object Literals

I am currently developing a nodejs application that needs to communicate with various network resources, such as cache services and databases. To achieve this functionality, I have created a module imported through the require statement, which allows the a ...

Having trouble retrieving the NextAuth session data within Next.js 12 middleware

I've been working on implementing route protection using Next.js 12 middleware function, but I keep encountering an issue where every time I try to access the session, it returns null. This is preventing me from getting the expected results. Can anyon ...

Tips for applying various CSS properties to a single element using styled-components

Is there a way to style similar elements differently using different CSS properties in styled components? For example: <div></div> <div></div> With the knowledge I have, I can do: export const StyledDiv = styled.div` color: red; ` ...

Styling text by reducing its size with CSS

Utilizing a CSS class to truncate text in the accordion header, which includes both a URL and plain text fields that need to be displayed on the same line. Desired Output: .../abc/xyz Count:42 Current output: .../abc/xyz Count:42/ (An odd slash is ...

What are the reasons behind loading failures and the subsequent failure to resolve promises?

Here is a snippet of code that is part of a larger directive: var imageArray = []; for (var i = 0; i < $scope.abbreviations.length; i++) { imageArray[i] = new Image(); imageArray[i].src = $scope.abbreviations[i].img ...

Cross domain request in a simple HTML document

I'm currently working on an app that is strictly in plain HTML files without a server. I'm facing difficulties with cross domain requests from JavaScript. Whenever I try to make a request, the browser displays this error message: XMLHttpRequest ...

Encountered a 404 error while attempting to build and serve a Vue.js project using 'npm build' in Apache Tomcat

After setting up a Vue.js project, the configuration in the package.json file looks like this: "scripts": { "serve": "vue-cli-service serve", "build": "vue-cli-service build", "lint": ...

The bundle.js file in the index.html document is not being loaded on the gh

I have recently organized a React project using webpack and now I am looking to publish this project on my personal site on Github. I have set up the user site repository with two branches - master and gh-pages. The structure of the project is as follows: ...

Identify the quantity of dynamically added <li> elements within the <ul> using jQuery

I'm facing an issue where I need to dynamically add a list of LI items to a UL using jQuery. However, when I try to alert the number of LI elements in this list, it only shows 0. I suspect that it's because the code is trying to count the origina ...

What is the best way to merge all project modules into a single file using the r.js optimizer?

While working with the r.js optimizer, I noticed that the final index.html file doesn't seem to allow for referencing just a single script without making any async calls to other scripts during a user's session. It appears to generate multiple gr ...