What is the best way to adjust the width of Bootstrap columns to match the length of the longest column in

The Challenge

In my task, I am dealing with a list featuring two columns. The issue that I am encountering is the desire for the left column to begin precisely where the longest column on the left ends. Presently, it initiates directly after the first column.

What steps should be taken to ensure that the second column commences where the longest section of the first one concludes?

https://i.sstatic.net/NiM3L.png

Current Appearance vs Desired Outcome

Attempts Made

I attempted incorporating row-fluid utilizing col for the initial column and col my-auto for the concluding column. In doing so, the alignment appeared accurate on moderate-sized screens. However, when viewed on smaller devices like cell phones, the text overlapped, whereas on larger screens, there was excessive spacing between them.

Snippet from code in The code section

<div class="row fluid">
 <div class="col">
   <label id="key" for="object.key"><b>{{object.key}}:</b></label>
  </div>
  <div class="col my-auto">
   <label id="object.key">{{object.value}}</label>
  </div>
</div>

I made an attempt to consult the documentation available at https://getbootstrap.com/docs/4.0/utilities/flex/, but unfortunately, was unable to pinpoint a solution to rectify my particular problem.

The Code

I created a basic Angular component called Two Column Array. Within this setup, I employed Bootstrap for formatting purposes. The main concept here is to dynamically display a list of information within a card layout.

HTML

<ng-container>
  <div class="card">
    <div class="card-header">
      <div class="card-fluid" *ngFor="let object of ListObjects" ng-class-odd='odd'>
        <div class="d-flex">
          <div class="mt-1">
            <label id="key" for="object.key"><b>{{object.key}}:</b></label>
          </div>
          <div class="mt-1">
          <label id="object.key">{{object.value}}</label>
          </div>
        </div>
      </div>
    </div>
  </div>
</ng-container>

Ts

import { Component, Input, OnInit } from '@angular/core';
import { ListTwoColumnObject } from '@models/list-two-column';

@Component({
  selector: 'app-two-column-list',
  templateUrl: './two-column-list.component.html',
  styleUrls: ['./two-column-list.component.css']
})
export class TwoColumnListComponent {
  @Input() ListObjects: ListTwoColumnObject[];
  constructor() { }
}

ListTwoColumnObject

export class ListTwoColumnObject {
  key: any;
  value: any;

  constructor(key: any, value: any){
    this.key = key;
    this.value = value;
  }
}

Example of Creating List

const objList = Array<ListTwoColumnObject>();
 objList.push(new ListTwoColumnObject('Fakturanr.', invoice.invoiceNr));
 objList.push(new ListTwoColumnObject('Betalt', convertBool.transform(invoice.isPaid)));
 objList.push(new ListTwoColumnObject('Ordre opprettet', 
 datePipe.transform(invoice.orderDate,'yyyy.MM.dd')));

Answer №1

In response to your query about whether a table will wrap the columns under each other if the screen size decreases, the answer is no. Tables do not rearrange rows vertically to accommodate smaller screens; they simply adjust in size horizontally. However, given that you only have two columns of data, even on an older smartphone with a 320px wide display, you should be able to fit the content without needing a vertical scroll.

If your content exceeds the height of the screen, a vertical scroll will be necessary to view it all.

<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c1a3aeaeb5b2b5b3a0b181f5eff7eff1">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>

<div class="container" lang="no">
    <div class="row justify-content-center">
        <div class="col-12 col-sm-10 col-md-8 col-lg-6">
            <div class="card">
                <div class="card-body">
                    <table class="table table-borderless">
                        <tbody>
                            <tr>
                                <th scope="row">Invoice No.:</th>
                                <td>100</td>
                            </tr>
                            <tr>
                                <th scope="row">Paid:</th>
                                <td>Yes</td>
                            </tr>
                            <tr>
                                <th scope="row">Order created:</th>
                                <td>2021.01.06</td>
                            </tr>
                            <tr>
                                <th scope="row">Due Date:</th>
                                <td>2021.01.16</td>
                            </tr>
                            <tr>
                                <th scope="row">Created by:</th>
                                <td>edit</td>
                            </tr>
                            <tr>
                                <th scope="row">Order type:</th>
                                <td>Settled late</td>
                            </tr>
                            <tr>
                                <th scope="row">Amount:</th>
                                <td>450</td>
                            </tr>
                            <tr>
                                <th scope="row">Paid amount:</th>
                                <td>-450</td>
                            </tr>
                            <tr>
                                <th scope="row">Remaining amount:</th>
                                <td>0</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

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

Troubleshooting problem with video recording functionality using HTML 5 media streams

My HTML 5 code for video recording and uploading is encountering a JavaScript error when the start button is clicked. The error messages I am receiving are: "TypeError: webcamstream.record is not a function streamRecorder = webcamstream.record();" "TypeE ...

Issue encountered while importing ComponentResolver in an Angular 2 component

Currently facing an issue while trying to import "ComponentResolver" import { Component, HostListener, ViewContainerRef, ViewChild, ComponentResolver } from '@angular/core'; The error message I am encountering is: Module '"/home/maksym/ ...

HTML5 images not loading correctly upon initial load despite utilizing image.onload

Currently, I am developing a webapp using EaselJS and encountering an issue where, upon the initial load after clearing my cache, the images are loading in the top left corner at their default size (x:0, y:0, scale:1) instead of the specified position. I u ...

What is the best way to access the input element of ng-content from the parent component?

Creating a unique component in the following structure <div class="custom-search-field" [ngClass]="{'expanding': expanding}"> <ng-content></ng-content> </div> When using this component, users are expected to include ...

What are the steps to display the entire image instead of a cropped version?

Currently in the process of constructing a website using HTML/CSS/Bootstrap/Js. I have encountered an issue while attempting to overlay a jumbotron on a container with a background image utilizing z-index. Unfortunately, the background image I am using k ...

What sets apart a .class element from element.class in CSS?

I was browsing through this tutorial http://www.w3schools.com/css/tryit.asp?filename=trycss_nesting and noticed a confusing point. Why did they use .marked p instead of p.marked? When I tried changing it to p.marked, the text didn't turn white as expe ...

The remaining visible portion of a viewport is equivalent to the height of an element

Is there a way to dynamically set a div's height so that it expands from its starting position to the end of its parent div, which is 100% of the viewport minus 20 pixels? Here is an example of how you can achieve this using jQuery: $(document).read ...

Creating mobile-friendly buttons: a step-by-step guide

How can I make my button responsive? I have a button on an image within a slider. It looks good and works fine on desktop, but on mobile it appears too big and gets overlapped with the slider radio icons, causing the "read more" link button to not redirect ...

Exploring node.js Rest API and Angular 2 Application with Shibboleth Integration

Recently, a prestigious university expressed their desire for an application that utilizes Shibboleth authentication. They have their own Identity Provider (IDP) in place. For this project, I plan on developing a Node.Js backend and an Angular frontend. ...

Using Selenium Python to interact with HTML elements based on their text content

My task is to interact with an HTML element that has an id like <span class="a-button-inner"> <input name="submit.addToCart" aria-label="Aggiungi al carrello dal venditore VERONCART SRL con prezzo 775,00&nbsp;€ & ...

Click on the event to save the document and print the HTML page

Is there a way to create an onclick event that saves the current HTML page as a document and then prints it? <html> <body> <div class="reportformat"> <div class="format1"> <table> <tr ...

I would like to implement a delay on this button so that when it is clicked, there is a pause before navigating

When I add the delay, it doesn't work, and when I remove it, it does. What can I do to make this button have a href link that delays before redirecting to another page? (I'm a newbie) I need to click and wait 3 seconds before navigating to other ...

Tips for utilizing anchor links in Angular without altering the URL within the Angular framework

I am attempting to navigate from a element with the class "class1" to a div with the class "class2". However, when the link is clicked, the URL changes. This causes an issue where trying to go back results in returning to the current page at a different ...

bootstrap style list-group without overlapping

In the image below, you can see that I have a list of American states within a list-group class. My issue is that I am attempting to eliminate the whitespace and essentially move Arkansas below Alaska and so forth. Here is my current HTML and CSS: CodePen ...

Resolving the Blank Space Problem in DataTable CSS Styling

I encountered an unusual issue while working with DataTable in my project. Here's a link to view my DataTable example I have also attached a picture illustrating the problem I am facing. Is there a way to remove the blank space containing filter but ...

Navigating to Angular component following Jersey and Spring SAML Security Single Sign-On verification

I have a project in progress that utilizes Angular for the front end and Jersey integrated with Spring SAML Security for Single Sign-On (SSO) authentication. My attempt involved initiating the app from Angular (http://localhost:4200), which then makes an ...

Is it possible to utilize AJAX to split the text into two separate boxes instead of just one?

My HTML page is currently set up to fetch information from a database table and display it in a single text box. This process involves connecting to a PHP file using an AJAX function for handling the request. Now, I am considering the possibility of displ ...

Understanding the purpose of the notched property in Material-UI

I am currently integrating Material-UI into a project and exploring their API. One thing that I find confusing is the notched property within the OutlineInput Component. <FormControl variant='outlined'> <OutlinedInput notched={false} ...

Is there a way to make scrollTop function on iOS mobile devices?

I am facing an issue with a div that has CSS properties display: flex and position:fixed;. I am trying to scroll to the top of it. This functionality is working fine on all platforms except for iOS mobile devices. The scrolling does not work on iOS mobile ...

Creating individual background colors for each nested child element is achievable by using CSS selectors and the nth

I want to create a reddit comment layout similar to this: <div> <div class="comment" style="background: white;"> <div class="comment" style="background: grey;"></div> <div class="comment" style="background: grey;"> ...