Can the data cells of columns be dynamically adjusted to align them on a single vertical line?

For some time now, I have been grappling with a CSS issue. I am working with a table that has 3 columns displaying departures, times, and situational text for scenarios like delays or cancellations.

However, as evident from the images, the alignment of the third column is off due to the dynamic nature of the second column's text. Despite trying various CSS properties, I haven't been able to resolve this issue yet. Could it be related to the margin-left and margin-right properties?

View the table

CSS

.busStop .tilerow {
display: flex;
border-bottom: 2px solid var(--tavla-border-color);
padding: 1rem 0 0.75rem 0;

&__icon {
min-width: 2rem;
margin-right: 1rem;
font-size: 2rem;
}

&__label {
margin: 0;
margin-top: 0.25rem;

}

&__sublabel {
font-size: 1.25rem;
font-weight: 400;
margin-top: 7px;
margin-left: auto;
margin-right: 72%;
min-width: 5rem;
white-space: nowrap;

&__cancellation {
background-color: $colors-brand-white;
border-radius: 0.5rem;
height: 0.875rem;
overflow: visible;
width: 0.875rem;
}

&__situation {
font-size: 1.125rem;
height: 1.25rem;
margin-left: 72%;
width: 0.875rem;

}
}
}

index.ts

export function TileRow({ label, icon, subLabel }: Props): JSX.Element { return (

 <div className="tilerow">
<div className="tilerow__icon">{icon}</div>
<Heading3 className="tilerow__label">{label}</Heading3>
<div className="tilerow__sublabel">
{subLabel.time}
<SubLabelIcon subLabel={subLabel} /> 
</div>
</div>
)

}

Answer №1

Utilizing display: flex on .tilerow creates independent rows, explaining the varying widths in the 3rd column (Avgang).

Switching to display: grid on .busStop (removing flex) would be more suitable.

Below is a snippet that needs adaptation for React:

.busStop {
  display: grid;
  grid-template-columns: auto auto auto 1fr;
}

/* Since .tilerow__* are not direct children of .busStop */
.tilerow {
  display: contents;
}

.tilerow__item {
  margin: 0;
  padding: 1em;
  padding-left: 0;
  border-bottom: 1px solid grey;
}

.tilerow__label {
  font-size: 1rem
}
<div class="busStop">
  <div class="tilerow">
    <div class="tilerow__item tilerow__icon">{icon}</div>
    <h3 class="tilerow__item tilerow__label">{label}</h3>
    <div class="tilerow__item tilerow__time">Now</div>
    <div class="tilerow__item tilerow__sublabel">{subLabel}</div>
  </div>
  <div class="tilerow">
    <div class="tilerow__item tilerow__icon">{icon}</div>
    <h3 class="tilerow__item tilerow__label">{label}</h3>
    <div class="tilerow__item tilerow__time">Now</div>
    <div class="tilerow__item tilerow__sublabel">{subLabel}</div>
  </div>
  <div class="tilerow">
    <div class="tilerow__item tilerow__icon">{icon}</div>
    <h3 class="tilerow__item tilerow__label">{label}</h3>
    <div class="tilerow__item tilerow__time">1 minute</div>
    <div class="tilerow__item tilerow__sublabel">{subLabel}</div>
  </div>
  <div class="tilerow">
    <div class="tilerow__item tilerow__icon">{icon}</div>
    <h3 class="tilerow__item tilerow__label">{label}</h3>
    <div class="tilerow__item tilerow__time">2 minutes</div>
    <div class="tilerow__item tilerow__sublabel">{subLabel}</div>
  </div>
  <div class="tilerow">
    <div class="tilerow__item tilerow__icon">{icon}</div>
    <h3 class="tilerow__item tilerow__label">{label}</h3>
    <div class="tilerow__item tilerow__time">10 minutes</div>
    <div class="tilerow__item tilerow__sublabel">{subLabel}</div>
  </div>
</div>

UPDATE: In this scenario, I believe implementing <table> could have been a viable option.

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

React hooks problem with toggle arrow functionality

Could anyone assist me with the following issue: I have a React Hooks component where I am trying to toggle an arrow when clicking on a span element. It currently works only once, and if clicked again, it does not work anymore. I am confused as to why th ...

Open webview link in default browser when the link target is set to "_blank" in React Native

I'm working with a WebView that has multiple links inside. If one of those links is selected and it includes a target="_blank" attribute, how can I make it open in the default browser? <WebView ref={webViewRef} source={{ uri: ' ...

Is there a way to remove the initial number entered on a calculator's display in order to prevent the second number from being added onto the first one?

I am currently in the process of developing a calculator using HTML, CSS, and JavaScript. However, I have encountered an issue with my code. After a user inputs a number and then clicks on an operator, the operator remains highlighted until the user inputs ...

Combining the p class with flexbox for optimal layout design

I have four flexed container boxes and I am looking to add text below them in a row. Does anyone have suggestions on how I can achieve this alignment, as well as tips for optimizing the code? .container { display: flex; flex-direction: row; just ...

Centering the scrollIntoView feature on mobile devices is presenting challenges with NextJS applications

Description While navigating on mobile browsers, I'm facing a challenge with keeping an element centered as I scroll due to the browser window minimizing. I've experimented with different solutions such as utilizing the react-scroll library and ...

Modify the button's background color for Django's image upload field

In one of the forms in my Django application, I have included a field that allows users to upload an image. Here is the code for this field: image = models.ImageField(upload_to=upload_location, null=True, blank=True) To display this field in my form tabl ...

Pause animation when hovering over their current positions

I am working on a project with two separate divs, each containing a circle and a smiley face. The innercircle1 div is currently rotating with a predefined animation. My goal is to create an effect where hovering over the innercircle1 div will pause its rot ...

The error `TypeError: Unable to access properties of an undefined value (reading 'authService')` occurred

I'm attempting to check if a user is already stored in local storage before fetching it from the database: async getQuestion(id: string): Promise<Question> { let res: Question await this.db.collection("questions").doc(i ...

Implementing data waiting strategy in Vue component using TypeScript for rendering

When working with the first component, I encountered a scenario where I needed to open a new page using the router functionality: In Component_1.vue: let route = this.$router.resolve({ name: 'Schedule', params : { id: (this.schedule[0].schedule ...

Navigating intricate pathways in NextJs

I'm currently facing a challenge with implementing descriptive routes in my NextJs application due to the file-based routing system it uses. The desired route on the web is: (/posts/id/mail); Here's how I have structured it in the project: Posts ...

Is there a way to insert and store a personalized field in the WordPress Gutenberg (block editor) dashboard?

https://i.stack.imgur.com/FZvts.png I'm currently working on my portfolio and am looking to include a gallery field. I couldn't figure out how to add a custom field in the screenshot provided. Does anyone have any insights on how this can be ach ...

Avoid jQuery ContextMenu Submenu Items from Expanding in Size on Mobile Devices

Recently, I started using the jQuery contextMenu which can be found at . The issue I encountered involves a menu with a submenu. Whenever I try to access the submenu items on mobile Safari or Chrome, the size of the menu items suddenly doubles and gets cu ...

Codesandbox is experiencing a technical issue where the React library is not being identified. However,

Just wanted to showcase some example code on Codesandbox, but this particular code in MyTable.tsx import { FC, useState } from "react"; interface Row { id: number; content: string; } interface Props { initialRows: Row[]; } export const M ...

I am encountering an issue while attempting to set up admob for my react native application, as I am facing

Encountering an error The file "/BuildProductsPath/Release-iphoneos/XCFrameworkIntermediates/GoogleAppMeasurement/WithoutAdIdSupport/GoogleAppMeasurement.framework/GoogleAppMeasurement(APMAdExposureReporter.o)" does not have bitcode. Suggestions include r ...

What is preventing bots and crawlers from detecting Next.js meta tags?

I'm currently using Next.js with Typescript and MongoDB to retrieve data. I'm encountering difficulties in rendering the page because the crawler is unable to detect the meta tags. For instance, Bing Search Engine claims that Title and Meta desc ...

Using i18next to alter language in a React app

Implementing the i18next translation system into my React app was a breeze thanks to a helpful guide I found. However, I'm facing an issue with changing the language manually. The guide covered the setup process perfectly, but lacked information on ho ...

Updating a React component upon pressing a button to trigger a re-render

Currently, I am in the process of developing a React component that allows users to input an ID and retrieve relevant information upon submission. The code for this component is structured as follows: export default class IDContainer extends React.Componen ...

Unveiling the Theme: Navigating the Material UI withStyles and WithTheme for Theme

const StyledSlider = withStyles({ root: { color: theme => theme.palette.primary.main } }, { withTheme: true })(Slider); Initially, I thought the withTheme option would allow access to the theme inside the withStyles function. However, since the t ...

Encountered an ERESOLVE error when attempting to install a package, unable to resolve the dependency tree

After attempting to install the necessary dependencies for my project with npm install, an error message came up that I am unable to decipher: npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: &l ...

Which state management tool am I employing - the NEW context API or good ol' Redux?

After learning React and mastering the use of the Context API, I recently heard about a "new context api." Since I learned React from an older course in late 2017, I'm unsure whether I'm using the new or old Context API. Furthermore, upon discove ...