Managing margins that vary across situations

I've hit a snag while working on a project where I'm using react.js with styled-components. The issue lies in styling invoice cards within a list, where the content of each card varies based on JSON data. The problem specifically revolves around spacing; since the content differs, assigning a fixed margin results in layout inconsistencies. This leads to an undesired outcome like this Link to the image of the problem instead of the intended appearance demonstrated here what it should be. As depicted in the design, all cards should align at the same level. When attempting to address this by adding min-width to elements like ID, name, and date, it introduces another spacing issue between the name and price fields. Below is the code snippet for this component.

import React from "react";
import styled from "styled-components";
import { ReactComponent as RightIcon } from "../../../images/icon-arrow-right.svg";
import data from "../data/invoices.json";

/* Styled components declarations */

const InvoiceCard = () => {
  const renderInvoices = data.map((invoice) => {
    /* Extracting date details */
    
    return (
      /* Rendered JSX structure for individual invoice cards */
    );
  });

  /* Rendering list of invoices */
  
};

export default InvoiceCard;

Your assistance on this matter would be greatly appreciated. Thank you!

Answer №1

For this scenario, it is necessary to specifically define the width for each column within every row. Subsequently, various styles can be applied to each column based on requirements (such as text-align, flex with justify-content, etc), ensuring uniform styling across all cells in the same column.

.row-wrap {
  display: flex;
}
.col-wrap {
  background: red;
  margin: 2px;
}
.col1 {
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  width: 200px;
  text-align: left;
}
.col2 {
  width: 300px;
  text-align: center;
}
.col3 {
  width: 150px;
  text-align: left;
}
.col4 {
  width: 400px;
  text-align: right;
}
<!DOCTYPE html>
<html>
  <head>
    <title>Parcel Sandbox</title>
    <meta charset="UTF-8" />
  </head>

  <body>
      <div class="row-wrap">
        <div class="col-wrap col1">text</div>
        <div class="col-wrap col2">text</div>
        <div class="col-wrap col3">text</div>
        <div class="col-wrap col4">text</div>
      </div>
      <div class="row-wrap">
        <div class="col-wrap col1">
          longgggggggggggggggggggggggggggggggggggggg text
        </div>
        <div class="col-wrap col2">text</div>
        <div class="col-wrap col3">text</div>
        <div class="col-wrap col4">text</div>
      </div>

  </body>
</html>

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

The issue with MUI material autocomplete not functioning properly when onBlur is triggered

Although the onFocus parameter is working fine in material autocomplete, I'm facing an issue with the onBlur parameter. Can someone explain why this might be happening and provide a correct solution to implement it? <Autocomplete onBlur={() ...

Typescript: Firebase App type does not include delete, installations, name, or options properties

Exploring the realm of Typescript and its compatibility with Firebase has been a recent endeavor of mine. I've created a FirebaseProvider that requires a Firebase app to be configured in the following manner: import firebase from "firebase/app&qu ...

Display or conceal div based on chosen options

I am working on a feature that involves three dropdown select boxes, each containing different sets of demographic attributes. My goal is to show a score based on the combination of selections made by the user. For example, if a user chooses Male, 18-24, A ...

Error: Headers cannot be modified after they have already been sent to the client due to form data issues

Encountering an issue with uploading an image to Azure storage blob. The fetch method doesn't seem to be working as expected. The process works fine in Postman but throws an error when using fetch. No issues found during deployment on Heroku. What ...

Having trouble getting the items to show up on the canvas

I have been struggling to implement JavaScript on a canvas in order to display mice in the holes using the mouse coordinates. Despite trying many different methods and spending close to a month on this project, I still can't seem to get it to work acr ...

exploring the power of Next.js with the utilization of getStaticProps and serverSide

My e-commerce website built with Next.js supports multiple languages. I'm looking for guidance on how to effectively utilize getStaticProps and getServerSideProps when dealing with both static and dynamic data. _app.js import {appWithTranslation} fro ...

The functionality of z-index is unreliable when article elements are utilized

Essentially, my goal is to display the <article id="characters"> above the <article id="accordion">. However, despite my efforts, the characters article appears below the accordion article instead of on top or even behind it. Where did I go wr ...

Is it necessary to bump the major version if I make updates to a react module that does not affect existing code functionality, but may cause Jest snapshot tests to break?

Imagine I am developing a module for a react component and currently working on a PR to introduce a new feature. Along with this new feature, I have also made changes to the component by refactoring it to eliminate certain internal parts that were previou ...

Attempting to display a singular form

Currently, I am working on a MERN app and encountering a small issue... I am developing an application where users can create rooms and within those rooms, they can plan their daily activities. It's similar to a TODO app but more intricate. I wanted ...

Issue with JavaScript function not triggering in Internet Explorer

Here is the code snippet I am working with: <body onLoad="subcatSelection();"> The function that should run on body load is located in a .js file that is included using this code: <script type="text/javascript" src="bincgi/search_lists.js"& ...

Transfer a JavaScript value to PHP via POST method without the need for submitting or refreshing the page

My website includes a Google Map feature that updates geocoordinates when the marker is dragged and displays the address. Currently, JavaScript is passing the X and Y values to an HTML "ID" using the "GET" method. However, I now need to pass these values u ...

Utilizing DataTable in Angular 2: A Step-by-Step Guide

I am struggling to implement the DataTable in my Angular 2 application. It seems like adding a script tag directly into templates is not supported in Angular 2. Can anyone guide me on how to make this work? I have a feeling that I need to make some adjustm ...

Exploring the various form types supported by 'react-hook-form'

I utilized react hooks form to create this form: import React from "react"; import ReactDOM from "react-dom"; import { useForm, SubmitHandler } from "react-hook-form"; import "./styles.css"; function App() { type ...

Trouble with Background Image Display in Internet Explorer 8

I have been attempting to set a background image for the . element, but it is not displaying correctly. The image shows up in Firefox and Chrome, but not in Internet Explorer. I have included a link to my website and relevant CSS code below. Can anyone pro ...

Wave your way to unique text creation with Firefox

Hey there, I've got some text inside a div that's been transformed with rotate(3deg). Strangely enough, in Firefox, the text appears wavy. When I remove the transform property from the div, the waviness disappears. Is there any way for me to keep ...

Transforming HTML features into PHP scripts. (multiplying two selected values)

I am currently working on converting these JavaScript functions into PHP in order to display the correct results. I need guidance on how to use PHP to multiply the values of the NumA and NumB select options, and then show the discount in the discount input ...

The 'target' property is not found on the specified 'string' type

I've encountered an issue while creating a search bar in Typescript. Despite my efforts, the input is not being recognized. It seems that whenever I use the term 'target' in my onChange method, it triggers an error stating: Property &ap ...

Overflow of dropdown menus in HTML CSS

Hello, I am new to both html and stack overflow. Please forgive me if this question has already been asked, as I couldn't find anything (but maybe I didn't search enough?). I have tried using overflow and clear properties, but I am struggling to ...

If the <option> "anyTableName" </option> is chosen, then display the column names of the selected table (PHP, MySQL)

Hey there, I'm a newbie on stackoverflow so feel free to correct me if I'm off base ;) Here's my current dilemma: I have a text.php file that contains 2 <select> elements. The first one allows me to choose a table (like "accounts", "c ...

Is there a way to quickly toggle between CSS properties in the Styles tab of Chrome Devtools/Inspector using a keyboard shortcut?

While I typically rely on Firefox and Firebug for CSS testing and tweaking, I am now trying to transition to Chrome. One issue that is really frustrating me is that in Chrome, changing a CSS property seems to require clicking on it, deleting the current va ...