Aligning diverse materials to create control components in a horizontal manner

I am facing a challenge in aligning the radio/checkboxes horizontally within different types of Angular Material form controls in a list. The list comprises mat-list-option, mat-checkbox, and mat-radio-button elements. I aim to have left-aligned labels with right-aligned checkboxes/radio buttons.

I attempted using fxLayouts "row" and "space-between" but couldn't achieve the desired alignment. I also experimented with CSS adjustments without success. Here is a StackBlitz demo: https://stackblitz.com/edit/material-6-kj87kz

<mat-selection-list>
  <ng-container *ngFor="let text of texts">
    <mat-list-option [checkboxPosition]="'after'">
      {{ text }}
    </mat-list-option>
    <div style="padding: 0 16px">
      <mat-checkbox *ngIf="isCheckbox" fxLayout="row" fxLayoutAlign="space-between center">
        {{ text }}
      </mat-checkbox>
      <mat-radio-group *ngIf="isRadioGroup" fxLayout="column" fxLayoutAlign="space-between center">
        <mat-radio-button *ngFor="let subText of subTexts" fxLayout="row" [labelPosition]="'before'">
        {{ subText }}
        </mat-radio-button>
      </mat-radio-group>
    </div>
  </ng-container>
</mat-selection-list>

I have simplified the code by removing bindings, conditions, and actions. However, achieving proper alignment remains a challenge. This is the current layout:

The struggle continues in getting the controls aligned correctly. Can anyone suggest an effective approach to address this issue?

Explore the StackBlitz demo: https://stackblitz.com/edit/material-6-kj87kz

Answer №1

To style the form checkbox and radio components, use the ::ng-deep selector. By applying some flex properties and adding space-between, you can achieve this customized look:

Example Link

.custom-checkbox,
.custom-radio-group {
  height: 48px;
  padding: 0 16px;
  display: flex;
  align-items: center;
}

:host ::ng-deep .custom-checkbox-layout {
  display: flex;  
  width: 100%;
  justify-content: space-between;
}

:host ::ng-deep .custom-checkbox-label-before .custom-checkbox-inner-container {
  margin-right: 0;
}

.custom-radio-group {
  align-items: flex-start;
  flex-direction: column;
}

.custom-radio-button {
  width: 100%;
  height: 48px;

  display: flex;
  align-items: center;
}

:host ::ng-deep .custom-radio-label {
  width: 100%;
  display: flex;
  justify-content: space-between;
}

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

What is the method to deactivate OverlayScrollbars when the window width is exactly 600px?

I am utilizing the overlayScrollbars plugin to create a custom navigation bar. Currently, I have set it up so that when the window width is less than 600px, the navbar behaves like a sidebar. <ul> <li>test 1</li> <li&g ...

What is the best way to display a background image at the top of a webpage and ensure it fills the entire visible area of the screen?

I'm a beginner in the world of development, and I've been given a challenging task to tackle. The assignment is to create a one-page website with navigation links for 'About Us' and 'Contact Us'. Upon clicking these links, th ...

The Bootstrap popover is displaying over a distinct element, rather than its designated trigger

I am trying to make the popover display near a different element rather than the trigger. My current setup looks like this: $triggerElement.popover({ title: varTitle, content: varContent, html: true, placement: 'auto top', tr ...

24-hour countdown tool featuring a visual progress bar

Currently, I am in the process of developing an application aimed at assisting individuals in either forming new habits or breaking old ones. In this application, I am looking to implement a countdown timer that ticks down daily; with the help of this help ...

Prevent line breaks caused by the span tag in Bootstrap 5

I have been attempting to use white-space:nowrap; to prevent the span tag in this text from causing a line break, but so far I have not been successful. The class styles used here are all standard Bootstrap 5 CSS class styles. On wider screens, the time i ...

Safari: Fixed-positioned DIVs staying put after DOM updates

Hey there! I've been experimenting with animating absolutely positioned DIVs on my webpage using some JavaScript to update the top and left CSS properties. It's been working smoothly in Chrome, Firefox, and even Internet Explorer 8. However, I e ...

Building a custom server rack table using PHP and MySQL is a great way to optimize your

I am in the process of developing a rack server using PHP and MySQL. My first task is to set up a dynamic table with rowspan functionality, followed by implementing drag-and-drop features using Ajax. Although I have researched various resources and attemp ...

"An issue of type TypeError occurred: When logging out of the application, it appears that 'x is null

Currently in my app, I am working on implementing authentication following the guidance provided in this example: Click here for more information. However, I have encountered an error that reads "ERROR TypeError: 'x is null'" when trying to execu ...

Guide to creating a disappearing and reappearing navigation bar in Angular2 when scrolling

I am attempting to recreate the functionality of a scroll-triggered header hiding feature implemented in Angular 2. Below is the code snippet I'm working with: // Hide Header on on scroll down var didScroll; var lastScrollTop = 0; var delta = 5; va ...

How to adjust the size of an SVG image on an HTML webpage

I've got an SVG file nestled inside my HTML code, and one of the cool things I've learned about this format is its ability to stay crisp and clear even when zoomed in. Typically, with a JPEG file, you might store it as a small 50 by 50 icon, the ...

Is there a way to adjust the opacity of a dropdown menu as I choose different options?

I encountered a situation where I have a compact box displaying a dropdown menu. While navigating through different options in the dropdown, a green box appears with the message "Press enter to select," obscuring the content underneath. How can I adjust i ...

Preventing data binding in an Angular 2 Kendo grid

Looking for a solution to improve performance on a page with a Kendo grid that contains a high number of rows. Each row has complex logic for showing/hiding elements based on column values, which is causing performance issues when dealing with 100 or mor ...

The Mat-paginator is refusing to align to the right edge when scrolling the table horizontally in an Angular application

https://i.sstatic.net/l0cZ4.png Overview: My Angular component features a table with Angular Material's mat-table and paginator. Despite fetching data from a source, the paginator fails to float right when I scroll horizontally. Sample Code: <!- ...

Only the initial letter of the angular input is returned by the event

Question: Why is the event only capturing the first letter of the input form? Background: In an input form, users can type a string but the method I created to handle the event is only recognizing the first letter entered. For example, if someone types "h ...

Sharing a let value within *ngFor loop from template to .ts file - here's how

Is it possible to use the async pipe to share the interpolation value {{ticketType.name}} with the .ts component in order to work with this value efficiently? Here is a sample of the template code: <mat-option *ngFor="let ticketType of ticketTypes ...

What is the process for adding tailwind CSS via npm?

Before, I was including Tailwind using a CDN. Now, I have installed it with npm and all three .css files are included, but the styles are not appearing in my HTML document. Here is the directory structure and a link to style.css The content of tailwind.c ...

Extracting the input's data and placing it into a table cell

Hey there! I am facing an issue where the data entered in the input fields is not getting transferred to the respective <td>. The text displayed in the (tabios) field should change according to what is entered in the input. Here's the code snipp ...

CSS problem, column does not remain in position unless filled with content

I am facing an issue with three floats in my layout. Two sections are exactly the same, but one of them loses its shape unless text is added to it. Here is my HTML: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.d ...

Redirect is not taking place in Django upon logging in

When trying to access my localhost at 127.0.0.1:8000, I have set up a Login page, but after logging in, it doesn't redirect to the "Automation page (form_name_view)". Note:- Clicking the login button does nothing whether the credentials are correct o ...

Achieving a compressed display of an HTML table

My boss recently asked me to enhance the responsiveness of a table on our website. I initially followed the solution discussed in my previous query about making tables responsive (Responsive Table Display) However, after completing that implementation, I ...