Equalizing the space between table headings and content

I am struggling with aligning the heading and entries in my table properly.

https://i.stack.imgur.com/IYtY1.jpg

My goal is to ensure that the heading and entries are perfectly aligned with each other.

This is how my Table.jsx looks like:

<div className="home-trending">
      <h1 className="home-trending-heading"> CRYPTO TRENDING ON DEX</h1>
      <div className="cex-trending-data">
        <div className="dex-content-heading bold">
          <p className="cex-content-heading-item">Chain</p>
          <p className="cex-content-heading-item">Token Amount (out)</p>
          <p className="cex-content-heading-item">Token Amount (in)</p>
          <p className="cex-content-heading-item">TXN Value</p>
          <p className="cex-content-heading-item">Wallet Type</p>
          <p className="cex-content-heading-item">Time</p>
          <p className="cex-content-heading-item">Twitter</p>
        </div>
        {topDEXTrades.slice(0, 10).map((trade) => {
          return (
            <TrendingDexRows
              chain={trade.chain_name}
              time={trade.trade_time}
              token_out={trade.token_out}
              token_in={trade.token_in}
              trade_id={trade.id}
              symbol_out={trade.symbol_out}
              symbol_in={trade.symbol_in}
              value={trade.txn_value}
              hash={trade.txn_hash}
              wallet={trade.wallet}
              category={trade.category}
              timeToGo={timeToGoSec}
              href={twitterHref}
              detailedView={true}
              view="large"
            />
          );
        })}
      </div>
    </div>

And this is my Table.css styling:

.dex-content-heading {
  display: flex;
  justify-content: space-between;
}

As for the Rows.jsx, here is a snippet of the code:

<div>
      <div className="cex-trending-row">
        <div className="cex-trending-row-name row-item">
          <img
            src={chainIcon(props.chain)}
            alt="btc"
            className="base-asset-img"
          />
          <p className="trending-symbol">{props.chain}</p>
        </div>
        <p className="row-item bold">{millify(props.token_out)}</p>
        <p className="row-item bold">{millify(props.token_in)}</p>
        <p className="row-item bold">{millify(props.value)}</p>
        <p className="row-item" style={categoryStyle(props.category)}>
          {categoryName(props.category)}
        </p>
        <p className="row-item"> {props.timeToGo(props.time)}</p>
        <div>
          <a
            href={props.href(
              props.value,
              props.token_out,
              props.token_in,
              props.chain,
              props.symbol_out,
              props.symbol_in
            )}
            target="_blank"
            rel="noreferrer"
            style={{ textDecoration: "none", paddingRight: "25px" }}
          >
            <img
              src={Twitter}
              alt="twitter"
              className="graph-icon-img-dex"
              style={{ marginLeft: "10px" }}
            />
          </a>
        </div>
      </div>
      <hr className="horrizontal-line" />
    </div>

Lastly, the Row.css contains the following styles:

.cex-trending-row {
  display: flex;
}
.row-item {
  flex: 1;
}

The issue I am facing is that the heading and rows are not aligned as desired. How can I ensure both are perfectly aligned? Is there a specific flex property that should be used to achieve equal spacing between items in both divs?

Answer №1

Check out this demonstration of utilizing grid in React.

const App = () => {
    const headingData = [
      "Chain",
      "Token",
      "Title 3",
      "EzPz",
    ];
    const dataArr = [
      { chain: "curve", token: "4m", foo: "bar", lemon: "squeezy" },
      { chain: "bird", token: "5m", foo: "tar", lemon: "teasy" },
      { chain: "lard", token: "1m", foo: "guitar", lemon: "jeezy" },
      { chain: "hard", token: "20k", foo: "blar", lemon: "measly" },
      { chain: "charged", token: "ayyyy", foo: "mars", lemon: "⚰" },
    ];
  
    return (
        <div className="myGrid">
          {
            headingData.map(str => <div key={"head-" + str}>{str}</div>)
          }
          {
            dataArr.map((o,i) => [
              <div key={"data-chain-"+i}>{o.chain}</div>,
              <div key={"data-token-"+i}>{o.token}</div>,
              <div key={"data-foo-"+i}>{o.foo}</div>,
              <div key={"data-lemon-"+i}>{o.lemon}</div>,
            ])
          }
        </div>
    );
};

ReactDOM.createRoot(
    document.getElementById("root")
).render(
    <App />
);
.myGrid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}
<div id="root"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.1.0/umd/react.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.1.0/umd/react-dom.development.js"></script>

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

Navigating a JSON object in ReactJS: key and value retrieval

Objective: Retrieve key and value pairs from JSON data using ReactJS. When the value is accessed with this code={this.state.myData}, it returns the following JSON data: "list":[ { "id": "1", "first_name": "FirstName", "last_name": "LastName ...

The error encountered is: `Exception: startDate.getTime is not a valid function

const [currentDate, setCurrentDate] = useState(new Date()); const fetchDataFromAPI = () => { let timeStamp = Number(currentDate.getTime()); axios.get( `https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=BTC,USD,EUR& ...

I encountered an error while trying to set up material-UI on VS Code using npm. Any suggestions on how to resolve this issue?

npm ERR! Unable to resolve dependency conflict: npm ERR! The root project requires react@"^18.1.0" npm ERR! but @material-ui/core expects peer react@"^16.8.0 || ^17.0.0" npm ERR! npm ERR! To fix this issue, you can try using --force o ...

What causes two identical pages to display fonts in different ways?

Two identical pages, hosted on the same server with the exact same Apache configuration and home directory. Each page contains only one sentence of text, unstyled. The strange thing is, when viewed in Chrome and Safari, the fonts render differently, while ...

Is there a way to enlarge images when hovered using canvas?

I came across a fascinating example at the following link: , where the images expand when hovered over. I am aware that this can be achieved using jquery, but I have concerns about its speed and reliability. I would like to experiment with d3.js, although ...

What is the starting point of a Next.js application?

When deploying a nextjs app on c-panel hosting, it requires the entry point of the application which is typically set as app.js by default. In a regular React application, you have full control over this aspect, but with nextjs, it's not always clear ...

Utilizing CSS variables and HSLA, create a distinctive linear gradient styling

I am encountering an issue with a CSS variable: :root{ --red: hsl(0, 100%, 74%); } Despite defining the variable, it does not work in the following code snippet: .page-wrapper{ background-image: linear-gradient(hsla(var(--red),.6), hsla(var(--red),.6 ...

Enhancing the level of abstraction in selectors within Redux using TypeScript

Here is a custom implementation of using Redux with TypeScript and the connect method. import { connect, ConnectedProps } from 'react-redux' interface RootState { isOn: boolean } const mapState = (state: RootState) =&g ...

"Selecting options from a range - Bootstrap multiple

Currently, I am in the process of implementing a multiple-choice tick box for PHP. The code I have so far is as follows: <div class="container"> <div class="row"> <div class="col-lg-6"> <div class="input-group"> <span class="inp ...

Horizontally align the label with the Checkbox

Hi everyone, I'm new to this forum and I've encountered a problem that I am struggling to resolve. The issue lies with a table containing a checkbox list. Initially, everything looks fine when I use: display:inline-block; However, on small ...

The alignment of elements on the right and left sides is not functioning as intended

I've been facing an issue with the alignment of my floats on my brand new website www.unicmedia.nl/case/oranje. Surprisingly, they seem to work fine in IE this time, but Firefox and Chrome are completely out of sync. Despite trying numerous solutions ...

What could be causing my input box to act strangely when users attempt to input information?

I seem to be facing an unusual issue with the <input onChange={this.handleArticleId} value={this.props.articleIdValue} placeholder="article id"/> field. Whenever I try typing something, the letter only appears in the input box after clicking on the s ...

When transitioning to mobile size, I aim to maintain the consistent design of my background-color circle using Bootstrap 5

I am working on creating a card design with a colored background instead of an image. However, I am facing an issue where the rounded-circle background color changes to an ellipsoid shape after passing the mobile size (sm or xs). Here is what I am aiming ...

What methods can I use to ensure my images are optimized for mobile users?

I have gone through several other discussions related to this issue, but none of the suggested solutions are working for me. Even with max-width: 100% and height: auto, the images remain unresponsive. They appear fine on browsers like IE, FF, and Chrome on ...

"Despite being higher in position, the z-index is causing the element to be placed below

I am currently facing an issue with a dropdown menu that I am trying to add to a WordPress site using Visual Composer. The problem arises when I attempt to place the dropdown on top of a parallax section below it. Despite setting the z-index of the paralla ...

Adding an offset to a material-ui Grid is a simple process that can

Looking to create a compact 'Item added' popup dialog with material-ui and its Grid system. Struggling to implement an offset feature similar to Bootstrap's col-sm-10 offset-1 using: <Grid container justify='center' alignItems= ...

Text being enveloped in a span tag

Currently, I have a table displaying a list of users with their corresponding roles. However, the roles column is sometimes wrapping before reaching the end of the line. The user list data looks like this: $scope.userList = [{ "id": 1, "name":"AB ...

React components receive props as an empty array when they are being passed to the component

I am passing a state to a component as a prop in the following way: componentDidMount() { axios.get("path/to/data") .then(result => { this.setState({ receivedData: result.data, }); ...

Common mistakes encountered when utilizing webpack for react development

I'm currently following the exercises in Pro MERN Stack by Apress and have come across a webpack issue. Everything was running smoothly until I introduced webpack into the mix. Now, when I execute npm run compile, I encounter the following error: > ...

Using Selenium in Python, identify and choose a class

Hello, I am currently working on automating a process using selenium, python, and GLPI. I have been struggling with selecting a user from a menu bar, despite trying various methods like linkText, cssSelector, and xpath. I suspect I may be doing something w ...