Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

246
Views
Unable to align the Divider between Grid items

I want to have Divider between Grid item.

The output should be like this:-

Col 1 | Col 2 | Col 3

Though in my code I'm unable to see the Divider and also the items are aligned in vertical fashion.

import "./styles.css";
import { Grid, Divider } from "@material-ui/core";
export default function App() {
  const tempArray = ['Col 1', 'Col 2', 'Col 3'];
  return(
    <Grid container align='center' direction='column'>
      {tempArray.map((title)=>{
        return(
          <Grid container direction='row'>
            <Grid item xs>
              <strong>{title}</strong>
            </Grid>
            <Divider orientation='vertical' flexItem></Divider>
          </Grid>
        );
        }
      )}

    </Grid>
  );
}

Also, I'm not sure how I can skip the Divider for the last item.
Here's the code sandbox link.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

The Grids inside the Grid container need to have the xs prop set to true to allow it to share the available space (docs). Otherwise it will try to occupy the whole viewport width which is the default behavior.

I'm not sure how I can skip the Divider for the last item.

You can render the Divider conditionally based on the current index:

{i !== tempArray.length - 1 && (
  <Divider orientation="vertical" flexItem></Divider>
)}

Full working code:

<Grid container align="center">
  {tempArray.map((title, i) => {
    return (
      <Grid key={title} item container xs /* <------------------ add this */>
        <Grid item xs>
          <strong>{title}</strong>
        </Grid>
        {i !== tempArray.length - 1 && (
          <Divider orientation="vertical" flexItem></Divider>
        )}
      </Grid>
    );
  })}
</Grid>

Codesandbox Demo

about 4 years ago · Juan Pablo Isaza Report

0

I'm able to align it horizontally.

index.js

import "./styles.css";
import { Grid, Divider } from "@material-ui/core";
export default function App() {
  const tempArray = ["Col 1", "Col 2", "Col 3"];
  return (
    <Grid container align="center" direction="column">
      <Grid container direction="row">
        {tempArray.map((title, index) => {
          return (
            <Grid item xs key={index}>
              <strong>{title}</strong>
              <Divider orientation="vertical" flexItem></Divider>
            </Grid>
          );
        })}
      </Grid>
    </Grid>
  );
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!