I am trying to place any number of divs into 2 columns and if the divs/elements are odd then the last one adjusts in the center of the two columns something like this..
but currently I am getting each div in a single row.
-
Here is my code.
import "./styles.css";
import Typography from "@material-ui/core/Typography";
export default function App() {
const sampleDetails = {
sampleObservations: [
  {
    observationsId: 7,
    selected: true,
    value: "12:53",
    parentId: 2,
    name: "Time"
  },
  {
    observationsId: 4,
    selected: true,
    value: "11.4",
    parentId: 2,
    name: "Ph"
  },
  {
    observationsId: 8,
    selected: true,
    value: "12-03-21 2:06",
    parentId: 3,
    name: "Flow Date"
  },
  {
    observationsId: 9,
    selected: true,
    value: "120",
    parentId: 3,
    name: "Frequency"
  },
  {
    observationsId: 10,
    selected: true,
    value: "20",
    parentId: 3,
    name: "Sample Count"
  }
]
};
return (
<div className="App">
  <h1>Hello CodeSandbox</h1>
  <div
    style={{
      display: "flex",
      flexDirection: "row",
      justifyContent: "space-around",
      marginBottom: "30px"
    }}
  >
    <div>
      {sampleDetails.sampleObservations.map(function (item, i) {
        return (
          <div
            key={i}
            style={{
              flexDirection: "row",
              display: "flex",
              justifyContent: "space-around",
              alignItems: "left"
            }}
          >
            <h4 variant="subtitle1" style={{ marginRight: "5px" }}>
              {item.name}:
            </h4>
            <Typography>{item.value}</Typography>
          </div>
        );
      })}
    </div>
  </div>
  </div>
  );
}
A running sample can be found in codesandbox: https://codesandbox.io/s/stoic-cherry-trc7n?file=/src/App.js
 
     
    