Setting a constant height for both <p> and <input> elements in Bootstrap 4

Currently, I am editing a page in Angular 2 and am encountering an issue with height differences during transitions. This inconsistency is causing problems for me.

Can anyone advise on how to fix the height responsively and adjust the size of the custom-control (toggle/switch)?

https://i.sstatic.net/CnPYL.gif

    <ng-container *ngIf="!edit; then thenTemplate; else elseTemplate"></ng-container>
    <ng-template #thenTemplate>
      <div class="row col-12" *ngIf="header && value != null ">
        <strong class="col-xs-12 col-md-4">{{header}}</strong>
        <p class="col-xs-12 col-md-8">{{onValue == value ? onText : offText}}</p>
      </div>
    </ng-template>
    <ng-template #elseTemplate>
      <div class="row col-12" *ngIf="header">
        <strong class="col-xs-12 col-md-4">{{header}}</strong>
        <div class="col-xs-12 col-md-8 custom-control custom-switch ">
<!-- if add thiss works normaly style="height:2.5rem"-->
          <input type="checkbox" class="custom-control-input" id="{{key}}" (change)="onValueChanged($event)" [ngModel]="onValue">
          <label class="custom-control-label" for="{{key}}">{{onValue == value ? onText : offText}}</label>
        </div>
      </div>
    </ng-template>

https://plnkr.co/edit/y3KKE7PKyGIC6cDTQACD?p=preview

Answer №1

To see a full working example, you can check out this StackBlitz Link

If you want to remove the default margin applied to the p-tag, simply make sure your p-tag looks like this...

 <p class="col-xs-12 col-md-8 m-0">{{onValue == value ? onText : offText}} p</p>

All you have to do is add the Bootstrap margin class m-0 to the p-tag. The rest will function according to your preferences.

Answer №2

Ensure that the height of your checkboxes matches the height of the labels once they are both set.

<div class="row col-12" *ngIf="same-height-class header && value != null ">
    <strong class="col-xs-12 col-md-4">{{header}}</strong>
    <p class="col-xs-12 col-md-8">{{onValue == value ? onText : offText}}</p>
  </div>
...
<div class="row col-12" *ngIf="header">
    <strong class="same-height-class col-xs-12 col-md-4">{{header}}</strong>
    <div class="col-xs-12 col-md-8 custom-control custom-switch ">

and in css:

.same-height-class{
  max-height: 50px!important;
}

It may be challenging to provide assistance without a working example of the remaining code and style information.

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

securely employ the translate.instant() function

In my work with Angular 7, I have two files named arservice.json and enservice.json. These files are used in the code snippet below from app.module.ts: import {BrowserModule} from '@angular/platform-browser'; import {BrowserAnimationsModule} from ...

Ways to align multi-line text at the center within a concealed Division

Struggling with aligning a paragraph in a div vertically. The paragraphs are within sliding boxes triggered by hovering over an image. Unable to use display: inline-block due to the default state being set to display: none;. Seeking guidance on the best ap ...

Trouble Ensuring First Radio Button Is Checked in Angular 6

I'm working on setting the first radio button in a group to be checked by default. Within my application, I have 6 tabs each containing a set of scales that need to be displayed as radio buttons. The goal is to have the first button in each tab check ...

Issue with presenting dynamic information through Bootstrap 4 list group component

I am currently working on building a User Interface using Bootstrap 4. I have some dynamic data that needs to be displayed in list-group items as a dropdown menu. The data follows a tree-like structure. At the top level, we have Level 1, which contains Le ...

What is the best way to apply the 'active' class to a selected navigation link using JavaScript?

How can I use JavaScript to change the active click of a Bootstrap navbar based on which nav link was clicked? The issue is that the changes made by JavaScript are lost when the browser navigates to the corresponding page. MY CODE: document.querySelect ...

Utilize an ion-searchbar along with a FormGroup to ensure that searches are only performed when the entered value meets the minimum

I am attempting to create a search feature that will only begin searching when the inputted value is 3 or higher However, the method I have tried so far has not been successful :( Home.page.html <form [formGroup]="search"> <ion-se ...

Angular 2 RC 4's ViewUtils provider offers a range of functionalities for optimizing views

Is there a way to dynamically load a child component in a parent view? this.viewAddedSubscription = viewManager.viewAdded.subscribe((view) => { let injector = ReflectiveInjector.resolveAndCreate([new Provider('view', { useValue: view })] ...

Error: Unable to locate module 'react-bootstrap/Offcanvas'

What steps should I take to address this problem? I've successfully installed Bootstrap and React-Bootstrap, but the issue persists. ...

Strategies for manipulating the position of an SVG polyline

Is there a way to move the chevron symbol to the beginning of each accordion header instead of it being on the right side of the words? Any help with this would be appreciated. The code snippet is provided below. Please advise on how to reposition the pol ...

What is the best way to ensure that content fills the entire screen?

My goal is to position the footer at the bottom of the page. This is the initial code I tried: <html> <head> <title>Freds Cars, Trucks & Jeeps</title> <style> #container{ height: auto; ...

shard: the dropdown menu can be interacted with by clicking, but the options

Having trouble selecting an item from a dropdown menu on a modal using splinter. Despite the dropdown being visible and clickable, the selection is failing unexpectedly. (Pdb) dropdown = next(i for i in my_browser.find_by_xpath('//select[@name="exist ...

Discover the steps to incorporate a glowing effect into your custom progress bar using JavaFX

After successfully creating a custom progress Bar in JavaFX, my next step is to incorporate a glow effect into the progressBar. To achieve this, I have constructed an ellipse with a Gaussian blur effect and integrated the centerX of the ellipse into a tim ...

The Angular 2 component is experiencing difficulty in fetching data from the service

My current predicament is fairly straightforward - I am attempting to fetch data from an Angular 2 service, but the target array always ends up empty. Despite seeing that the API call returns data with a status of 200 and no errors are displayed in the con ...

How to automatically set focus in a text box when a Kendo Window is opened

I am working on a project where I need to set the focus on the first field of a kendo-window when it opens after clicking on a button. I used ViewChild to declare the field, but it is showing as undefined when the window is opened because it hasn't be ...

Unable to reset iframe style height in IE8 using JavaScript

I am encountering an issue with resetting the height of an iframe using JavaScript. Here is the code snippet I am working with: var urlpxExt = document.getElementById('urlPx'); urlpxExt.style.height = "200px"; While this approach works well in m ...

Execute the function if the element has a specific class; otherwise, execute a different function

Currently, I am working on a page where I need to make an element draggable. Upon clicking on the element, I add the 'active' class which expands the div along with the image inside it. Initially, the div is structured as... <div class="wor ...

Having trouble with a nonresponsive link on a website? Unable to hover over it

The website can be found at: I've been trying to click on the "Home" link on the left side, but it doesn't seem to work for me. Any thoughts on why this might be happening? ...

What is the best way to monitor the input parameter in a method?

In order to verify the execution of the line slidingItem.close() inside setTimeout(), it is necessary to test this specific line within the setTimeout function call. The onCompleteActivity method contains the logic for dispatching actions and opening a pag ...

Annoying AngularJS Scrolling Problem

I am facing an issue with a Container that loads multiple views <md-content flex id="content"> <div ng-view></div> </md-content> One of the loaded views has the following structure: <div layout="column" id="selection-whit ...

A guide to loading CSS and JavaScript files asynchronously

Is it possible to use loadCSS (https://github.com/filamentgroup/loadCSS/blob/master/README.md) to allow the browser to asynchronously load CSS and JavaScript? This is what I currently have in my head tag: <link rel="preload" href="http://zoidstudios. ...