The appearance of Bootstrap React Nextjs doesn't quite match what's shown in the documentation

I am developing the frontend of my application using a combination of bootstrap, react, and nextjs. I attempted to implement the example provided by react-bootstrap at https://codesandbox.io/s/github/react-bootstrap/code-sandbox-examples/tree/master/basic. However, instead of achieving a result similar to this: https://i.stack.imgur.com/BIBWK.png, my outcome looks completely different: https://i.stack.imgur.com/DDEBN.png.

Here are some troubleshooting steps I have taken:

  • Switching from the default bootstrap package to bootstrap@next
  • Importing Bootstrap in both the index.jsx file and the example.jsx file

Below is the relevant code snippet:

Example.jsx - same as codesandbox.
import 'bootstrap/dist/css/bootstrap.min.css'

import React, { useState } from 'react'

import Jumbotron from 'react-bootstrap/Jumbotron'
import Toast from 'react-bootstrap/Toast'
import Container from 'react-bootstrap/Container'
import Button from 'react-bootstrap/Button'

const ExampleToast = ({ children }) => {
  const [show, toggleShow] = useState(true)

  return (
    <>
      {!show && <Button onClick={() => toggleShow(true)}>Show Toast</Button>}
      <Toast show={show} onClose={() => toggleShow(false)}>
        <Toast.Header>
          <strong className="mr-auto">React-Bootstrap</strong>
        </Toast.Header>
        <Toast.Body>{children}</Toast.Body>
      </Toast>
    </>
  )
}

const App = () => (
  <Container className="p-3">
    <Jumbotron>
      <h1 className="header">Welcome To React-Bootstrap</h1>
      <ExampleToast>
        We now have Toasts
        <span role="img" aria-label="tada">
          🎉
        </span>
      </ExampleToast>
    </Jumbotron>
  </Container>
)

export default App

index.jsx

function HomePage() {
  return <div>Welcome to Next.js!</div>
}

export default HomePage

Output of npm list:

├── <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3052534249404470051e001e01">[email protected]</a>
├── <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d6b4b9b9a2a5a2a4b7a696e3f8e6f8e6fbb4b3a2b7e5">[email protected]</a>
├── <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cea8afbdbaa7a8b7e3ada1a1a5a7ab8efbe0fde0ff">[email protected]</a>
├── <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bed8dfcdcad7d8c793d4c9cafe8d908e908e">[email protected]</a>
├── <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b3d5d2c0c7dafb91bf90fd99dacad5cecd87cacb4dc94c8cacbcadfc4dfdffedfcccb88718381828586">[email protected]</a>
└── <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="aedcbacabbbebec3ecbabfbdb6acdadfc2ddccdedfa0cdc1d502cbc7c0">[email protected]</a>

UPDATE: When I include Bootstrap in index.jsx, none of the CSS seems to be applied.

Answer â„–1

In order to utilize bootstrap with nextJS, you must first install it.

npm install bootstrap@next 

Once the installation is done, remember to import the css files into your nextJS _app.js file.

// include bootstrap css 
import 'bootstrap/dist/css/bootstrap.css'// add your custom css files
import "../css/customcss.css";

export default function MyApp({ Component, pageProps }) {
      return <Component {...pageProps} />
    }

To ensure responsiveness, make sure to add the following code to your nextjs component.

<Head>
   <meta name="viewport" content="width=device-width, initial-scale=1" />
</Head>

Alternatively, you can also use a CDN for this purpose.

Answer â„–2

After a moment of reflection, it dawned on me that the code-sandbox is utilizing bootstrap 4.6 while I am working with bootstrap 5. Upon downgrading for testing purposes, everything started functioning as expected. (*facepalm*)

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

Applying CSS classes to a custom AngularJS directive: A step-by-step guide

Need to have a CSS class called tab for the nav HTML element, which will be used as a directive: <nav tab></nav> The expected interpretation is: <nav class="tab"> <a></a> <a></a> <a></a> ...

Tips for centering or aligning a component to the right using Material UI?

Is there an efficient method to align my button to the right of its parent in Material UI? One approach could be using: <Grid container justify="flex-end"> However, this would also require implementing another <Grid item />, which m ...

Fetching items from a MongoDB collection using an array of unique identifiers

Creating an API using node.js/express and MongoDB. I have two collections that are related in a many-to-many way, Users and Items. My goal is to retrieve all the items that a user is following. Each user has an array of item IDs. How can I query to fetch ...

Iron meteor is unable to locate simpl-schema

Currently, I am utilizing iron-meteor to scaffold meteor crud apps while following this informative tutorial. The issue arises after installing aldeed collections and other packages using the command below; iron add twbs:bootstrap aldeed:collection2 aldee ...

Create a Bootstrap grid that perfectly fits the viewport without any overflowing content

I'm currently utilizing Bootstrap 5 in an attempt to design a simplistic layout consisting of an MxN grid of cells, each of equal size. My goal is to have this grid fill the entire viewport without any scrollbars appearing in either direction. However ...

What is the best way to set up a server-sent-events broadcast feature in totaljs?

Let's imagine this situation: Client1 and Client2 are currently in session1 Meanwhile, Client3 and Client4 are part of session2 My aim now is to send event "a" to all clients in session1 exclusively. I came across this example: https://github ...

Encountering an issue during the initialization of a NextJS app due to an ENO

When attempting to create a Next.js App using npx create-next-app@latest, the build fails after about 10 seconds, and I encounter the following error: npm ERR! Windows_NT 10.0.19045 npm ERR! argv "C:\\Program Files\\nodejs\&bs ...

Refreshing a page will disable dark mode

I'm in the process of implementing a dark mode for my website using the code below. However, I've encountered an issue where the dark mode resets when refreshing the page or navigating to a new page. I've heard about a feature called localst ...

The clickable functionality of buttons and text labels in Vue is currently not working

When I try to input text into the registration page in vue, nothing happens when I click the register/login button. However, if I press TAB and then enter my password followed by another TAB and ENTER, it works. This is the code snippet for the login-box: ...

Bootstrap is causing issues with unidentified div elements

I recently embarked on creating a slideshow using HTML, CSS, and jQuery. After completing the slideshow, I decided to add an interactive page beneath it. To streamline the layout process, I opted to utilize Bootstrap. However, upon loading Bootstrap, I en ...

Building a custom CellRenderer in AGGrid using TypeScript within a React environment

Currently, I am utilizing React along with TypeScript and attempting to create a custom CellRenderer in AGGrid. My code is structured like this: PriorityCellRenderer.tsx import React from 'react'; function PriorityCellRenderer(props:any) { co ...

Learn how to easily update the chart title in real-time while hovering over tooltips in Highcharts using React JS

Looking for a solution to dynamically change the chart title on hover in Highcharts? Check out this JSFiddle example: http://jsfiddle.net/q4b7dvmx/1/ I attempted to use setState for this purpose, but it's not working perfectly. tooltip:{ enabled ...

Building Travis CI in a specific subfolder

Currently, I am faced with the challenge of setting up automated testing for the backend portion of a MERN stack project that I have developed. The structure of my directory consists of the root folder containing the .travis.yml file, along with separate b ...

When using node.js with MySQL, the insert statement with a WHERE clause does not execute properly

Snippet: function setValue(currentVal) { idOutput = currentVal; encodedVal = Base.encode(idOutput); var baseInsert = {ShortUrlCode: encodedVal}; console.log(idOutput); console.log(encodedVal); con.q ...

Encountering an error message that states "Unable to access property 'props' of null object while filling

Can anyone help me figure out the error in my React component code below? import React, { Component } from 'react'; import { Input} from 'antd'; import Form from '../../components/uielements/form'; import Button from '.. ...

Encountering an error with adding @babel/preset-react after importing from a React library

After creating a create-react-app, I decided to refactor some of the React components into my own private library called "myLibrary". This library was created using create-react-library and is located in a folder named "myLibrary", alongside the "myApp" fo ...

Eager loading two identical N:M models in SequelizeJS results in data being returned for one model while the other model does not

I am facing a perplexing issue with my models in Sequelize. I have three models - Link, Overlay, and Tracker. Both Overlay and Tracker have a many-to-many relationship with the Link model in MySQL database. Even though both Overlay and Tracker use identic ...

Implementing Conditional Loops with $.each in AngularJS

I am working with an array called vm.settings.tab_permissions. Within this array, I need to check if the role is equal to vm.heading and replace it with vm.data. If the role is not equal, I want to push vm.data to vm.settings.tab. However, my current cod ...

Error: Unable to retrieve current location using 'Geolocation' in React

import "./App.css"; import { useState, useEffect } from "react"; function App() { const [lat, setLat] = useState(null); const [long, setLong] = useState(null); const [data, setData] = useState(null); const [error, setError] = u ...

Tips for implementing and utilizing onclick functions in EJS

My goal is to develop a trivia game with interactive features. I aim to enable users to click on an answer, which will trigger a border effect and increase the points variable. Below is the layout of the entire page: <% include ../partials/boilerp ...