Using the justify-content:space-between property does not seem to be effective in a Nextjs

In my Next.js app, I am facing an issue with the justify-content: space-between; property not working as expected for two divs inside a container. However, justify-content: center; works fine. Interestingly, when I use the same code in an index.html file, it functions properly.

export default function Home() {
  return(
    <div className={styles.container}>
      <div>1</div>
      <div>2</div>
    </div>
  );
}

CSS file

.container {
  padding: 2rem 2rem;
  display: flex;
  justify-content: space-between;
}
.container div {
  color: red;
  font-size: 35px;
}

Answer №1

If you're experiencing issues with justify-content: space-between not working, it may be due to not setting the width of your div first. To resolve this, ensure you set the width of the div as shown below.

.wrapper {
  padding: 2rem 2rem;
  display: flex;
  width: //define the desired width here
  justify-content: space-between;
}

Answer №2

It appears that the use of "className" is incorrect and it should be replaced with "class."

<div class="container">
  <div>1</div>
  <div>2</div>
</div>

Here is the CSS code:

.container {
   padding: 2rem 2rem;
   display: flex;
   justify-content: space-between;
}
.container div {
  color: red;
  font-size: 35px;
}

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

Create HTML content to be inserted into an Excel spreadsheet

I am looking to generate a worksheet and insert HTML content into it using a loop. foreach(...) { Excel.Worksheet worksheet = (Excel.Worksheet)workbook.Sheets.Add( Missing.Value, Missing.Value, 1, Excel.XlSheetType.x ...

What is the best approach to integrating Keycloak with Next.js?

I have been attempting to authenticate in Keycloak within my Next.js application using @react-keycloak/nextjs. However, after successfully logging in, I keep getting redirected back to the Keycloak server and then back to the main page repeatedly until an ...

Exploring Material-UI in React: A guide to integrating and utilizing breadcrumbs

Can breadcrumbs be integrated using material-ui in a reactjs-based setup? If so, how can I go about implementing them? ...

React i18next provides a fallback language in case the specified language is not

In my React app, I have implemented i18next for translating files, using the following approach: i18next.js (original) import i18next from 'i18next'; import XHR from 'i18next-xhr-backend'; import detector from 'i18next-browser-lan ...

Troubleshooting steps for resolving an issue encountered when attempting to install modules using npm in a React application

After encountering issues while attempting to install certain npms, I took the step of deleting the entire node_modules folder in order to reinstall it with the hope of resolving the problem. Before deleting the folder, my project was functioning properly ...

Attempting to create a single function that can be utilized with numerous divs that share the same class in jQuery

Currently, I am working on creating a basic jquery gallery viewer. In my code, I have the following structure: <div class="photoset"> <img /> <img /> </div> <div class="photoset"> <img /> <img /> <i ...

Error: Prisma seed - encountering issues with undefined properties (unable to read 'findFirst')

I've encountered a strange issue when using prisma seed in my nextjs full-stack project that I can't seem to figure out. Normally, when running the app with `next dev`, everything works smoothly and the queries are executed without any problems. ...

Tips for transferring PHP variable from a drop down menu

Hello, I am currently working on creating a dropdown menu using the <select> tag. My goal is to have it so that when someone clicks on one of the options in the dropdown, a new window opens. Additionally, I want the PHP variable from the main page to ...

Strategies for minimizing duplicate code in React applications

I am looking for a way to minimize code repetition in my project. Within a div element, I display content that can consist of a title, detail, or both. In cases where there is content, a close icon needs to be positioned next to it. Here is the existing c ...

Angular Material Dropdown with Multi-Column Support

I'm working on customizing the selection panel layout to display items in multiple columns. However, I'm facing an issue where the last item in each column appears off-center and split, causing overflow into the next column instead of a vertical ...

Every time I enter npm start in the terminal, I consistently encounter this error

After developing a simple web app and posting it on my repository, I started encountering these persistent errors. npm ERR! code ELIFECYCLE – David 1 hour ago npm ERR! syscall spawn C:\Windows\system32\cmd.exe;C:\Users'usernam ...

Additional NextJS routes are not functioning properly on the server side

Currently, I have successfully set up a NextJS app on Firebase and it's working well up to a certain point. I can easily access the app using this URL: Now, my next goal is to create a new route that I can access via: The current file structure of ...

The never-ending dilemma of React: should we alter the state array or leave it in its original

My question is regarding state mutations. I came across a suggestion on Cannot see updates from child component through parent's callback (case array and push) that mutating state directly is not recommended. As demonstrated in https://codepen.io/jad ...

Trouble with CSS display in Internet Explorer 8

My website located at this link is working perfectly in IE 10 and IE 11, however, any version lower than that is causing the content to be displayed on the far left of the screen instead of centering it. I have tried tweaking the CSS but can't seem to ...

What is the best way to convert an Angular object into a string using a for-loop and display it using $sce in AngularJS?

Currently, I am rendering a block of HTML and directives using $sce.trustAsHtml. To achieve this, I utilized a directive called compile-template which enables the use of ng-directives like ng-click and ng-disabled. While it is possible for me to pass sta ...

I need some help with adjusting the number of rows shown per page in MaterialReactTable

I've been utilizing MaterialReactTable and my goal is to display only 5 items on each pagination page. Despite setting muiTablePaginationProps, I still see 10 items per page. How can I resolve this issue? <MaterialReactTable columns={columns} ...

Disabling a text area or mat-form-field within the same HTML file in Angular 9

Currently, I am working with Angular 9 and angular Material Reactive Forms. My goal is to disable certain fields without relying on the disabled status within formControl in the TypeScript file. Instead, I want to achieve this solely through HTML. Here is ...

Tips for customizing the appearance of a Bootstrap toggle switch

I'm struggling to customize my bootstrap toggle button. No matter what I try, I can't seem to make any styling changes take effect. All I really need to do is increase the width of the button, but even that seems impossible. Here's a link t ...

Unexpected outcomes when trying to sort and paginate React-Table

Experiencing unexpected results with react-table integration for pagination and sorting. Merged examples from the react-table repository. Encountering an issue where table hooks reset the page index on re-render, causing fetchData to be called twice during ...

Capacitor implementation of NextJS Server-Side Rendering

We are currently using Next.js with server-side rendering (SSR) and we are looking to integrate Capacitor.js into our app in order to make it compatible with both Android and iOS devices. However, it seems that this integration is only possible with static ...