How can I apply both Css and Bootstrap styles to an element in Next.js?

I'm having trouble incorporating the Bootstrap class sticky-top into another CSS style element. I attempted to achieve the same effect without Bootstrap by adding position: sticky, top: 0 in the CSS, but it didn't work as expected. The issue arises when trying to maintain the CSS class ${styles.profile_nav_css}.

import Link from "next/link";
import styles from "../styles.module.css";
export const Nav = () => {
  return (
    <div className={`sticky-top ${styles.profile_nav_css} `>
      <Link href="/profile" className="text-decoration-none">
        Dashboard
      </Link>
      <br />
      <Link href="/profile/add-vehicle" className="text-decoration-none">
        Add Vehicle
      </Link>
      <br />
      <Link href="/profile/hires" className="text-decoration-none">
        Hires
      </Link>
    </div>
@media (max-width: 420px) {
  .profile_nav_css {
    height: 10vh;
    border: 3px solid green;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    box-sizing: border-box;
  }
}

@media (max-width: 1500px) {
  .profile_nav_css {
    height: 100vh;
    border: 3px solid blue;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-sizing: border-box;
  }
}

Answer №1

Upon reviewing the code provided, it appears that an attempt is being made to utilize the Bootstrap class sticky-top in conjunction with a custom CSS class profile_nav_css to establish a sticky navigation bar. However, there are some issues that may be contributing to the problem.

Incorrect sequence of CSS classes: The order in which CSS classes are applied matters. In the JSX code, the sticky-top class is being applied before the custom class profile_nav_css. This could lead to the properties of the later-applied class overriding the previous ones. To ensure the Bootstrap class takes precedence, it is advisable to reverse the order of classes:

<div className={`${styles.profile_nav_css} sticky-top`}>

Conflict with custom CSS: It seems that styles have been defined for the class profile_nav_css in the CSS file. These styles might clash with those of the Bootstrap sticky-top class. When utilizing Bootstrap classes, it is best to avoid custom styles that could disrupt the intended functionality of the Bootstrap class. Consider removing the custom styles for .profile_nav_css. Here is the updated code snippet:

import Link from "next/link";
import styles from "../styles.module.css";
export const Nav = () => {
  return (
    <div className={`${styles.profile_nav_css} sticky-top`}>
      <Link href="/profile" className="text-decoration-none">
        Dashboard
      </Link>
      <br />
      <Link href="/profile/add-vehicle" className="text-decoration-none">
        Add Vehicle
      </Link>
      <br />
      <Link href="/profile/hires" className="text-decoration-none">
        Hires
      </Link>
    </div>
  );
};

By making this adjustment, the Bootstrap sticky-top class should be correctly applied, and your navigation bar should stick at the top of the page as intended. Hopefully, this resolves the issue.

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

Unable to view numbers on iPhone or ios device

I am facing an issue with displaying a phone number in the contact section on my website. The number shows up on desktop but not on my iPhone, even when I resize the screen to be smaller than my phone's display size. This issue has been tested on both ...

Attempting to call a nested div class in JavaScript, but experiencing issues with the updated code when implemented in

Seeking assistance. In the process of creating a nested div inside body > div > div . You can find more information in this Stack Overflow thread. Check out my JSFiddle demo here: https://jsfiddle.net/41w8gjec/6/. You can also view the nested div on the ...

Tips for breaking out of the foundation row and aligning with the right edge of the viewport

I have a CodePen example showcasing the Zurb Foundation grid. I am looking for a way to make a div extend to the right edge of the viewport while keeping the left edge in line with the grid as the viewport is resized. <div class="row"> <div cla ...

execute a different function once the animation has finished running with the .bind

When attempting to detect the completion of a CSS animation in order to remove a class, I encountered an issue where using .bind causes the animation end event to trigger even for the other function. You can view the complete code here. How can I ensure ...

Creating a DockerFile for Next.js deployment in Google Cloud Build on GCP

This Dockerfile is based on the recommendations provided in the official documentation. # To ensure dependencies are installed only when necessary FROM node:alpine AS deps # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a ...

How can I eliminate the outline from the modal backdrop using Material UI styling shown in the image provided?

https://i.stack.imgur.com/cBCzd.png After attempting to remove the border and box shadow, I am still encountering issues with lines appearing only when clicking on the modal body. The modal styling code has been omitted as it primarily includes flex styli ...

The current issue I am encountering with Next.js 13 API request involves a TypeError where I am unable to read properties of undefined, specifically when trying to read 'headers

I am attempting to make a request to route.ts located at /api/register from the client component register.js. Even though the user is registered in the database, I keep receiving this error message. Here is my route.ts function: export async function POST ...

Personalized application: uncaughtException: TypeError: Unable to access properties of an empty entity (reading 'prototype')

In my _app.js file, I am utilizing getInitialProps: import App from "next/app"; function MyApp({ Component, pageProps }) { return <Component {...pageProps} />; } MyApp.getInitialProps = async ({ Component, ctx }) => { const appCont ...

I encountered an issue while making customizations to my default next.config.js file. Despite attempting various solutions, I consistently encountered an error regarding the invalid src property

I'm currently trying to introduce some custom configurations into the next.config.js file. However, I keep encountering an error regarding an invalid src prop. Despite my attempts to troubleshoot in various ways, the error persists. // ...

Exclusive JQuery Mobile Styles

Although I enjoy using JQuery Mobile, I'm facing compatibility issues with my custom Javascript on the page. Despite everything functioning correctly without JQuery Mobile, adding the library causes problems that I've been unable to resolve. Ess ...

Alert: Potential shared module issue detected when updating swr from version 1 to version 2 within a NextJS application

I have decided to upgrade my swr package from version 1 to the latest version 2. Here is a glimpse of my package.json. I am currently utilizing React 18, NextJS 12, and Webpack 5 for this project, including the ModuleFederationPlugin integration. { " ...

Leveraging icons with Bootstrap 4.5

I am currently exploring how to incorporate Bootstrap 4.5 icons using CSS. Do you have any examples of code that could guide me on how to achieve this? I am specifically interested in understanding the required CSS declarations that would allow me to use t ...

Utilizing form data binding with multiple instances of forms in React

Parent Component Within my parent component, named Users, there is a snippet of code that includes the functions for adding and updating users: addUser(index, user) { var users = this.state.users var existingUser = users[index] if (existingUse ...

Choosing the right jQuery selector to target a section that contains div elements

Whenever the h2 element within a section is clicked, I want all the fields in that section to be displayed. For example, if the user clicks on 'Contact Information', the three form inputs (fields) below the Contact Information heading should appe ...

The sorting icon in jQuery Data Table's search option is not functioning

I am having an issue with jQuery DataTables. When using jQuery DataTables, it provides a default search option. However, the problem arises when I search for a particular record and if the content does not match or if I find a single record, then I need to ...

Implementing ESM in your next.config.js file is critical for optimizing

Currently, I am in the process of optimizing a Next.js project and came across the requirement to include type: 'module' in thepackage.json file. However, this led to an error being thrown: Error [ERR_REQUIRE_ESM]: Must use import to load ES Mo ...

What causes userAgent to be undefined within _app.tsx during the use of getInitialProps?

When I check the code below, I'm encountering userAgent being retrieved as undefined: const userAgent = context.req?.headers['user-agent'] ?? ''; The issue persists with isMobile, where it's also being returned as undefined a ...

The function .css() in jQuery is malfunctioning

This task should be a piece of cake... All I want is to hide the buttons when a user is logged in and display the log out button instead. jQuery().ready(function($) { if ($("body").hasClass("logged-in")) { $(".logged-out-button").css("display", " ...

What are the steps for creating a standalone build in nextJS?

Currently, I am undertaking a project in which nextJS was chosen as the client-side tool. However, I am interested in deploying the client as static code on another platform. Upon generating a build, a folder with all the proprietary server elements of ne ...

Having difficulty retrieving API data with getServerSideProps

I am attempting to retrieve a user's name from the JSON placeholder API and display it, but for some reason, it is returning as undefined. I am not sure what the issue could be. Any assistance would be greatly appreciated! function DisplayUser({ data ...