Utilizing the "row" and "column" attributes in Angular (Flexbox) results in significant spacing between input fields within the HTML code

I'm working on aligning 2 input fields side by side within the same line. To achieve this, I've been utilizing Flexbox. However, I've observed that when using Flex with both 'row' and 'column', it introduces extra spacing as shown in the image below:

Here is the code structure:

apidefs-disp.component.html

<div class="flex-disp-apidefs-container">
    <div class="flex-disp-apidefs-list">

        <kdc-apidefs-list></kdc-apidefs-list> 
    </div>
    <div class="flex-disp-apidefs-form">
        <kdc-apidefs-form></kdc-apidefs-form> 
    </div>
</div

apidefs-form.component.html

        <div class="row">

            <!-- Name -->
            <div class="col">
                <div class="md-form">

                    <input required type="text" id="materialapidefsFormName" class="form-control"
                        aria-describedby="materialapidefsFormNameHelpBlock" mdbInput formControlName="name" />

                    <label for="materialapidefsFormName">Name</label>
                    <mat-error
                        *ngIf="apidefsForm.controls['name'].hasError('required') && apidefsForm.controls.name.touched">
                        Name is required
                    </mat-error>

                    <mat-error
                        *ngIf="apidefsForm.controls['name'].hasError('maxLength') && apidefsForm.controls.name.touched">
                        maximum Length is 25
                    </mat-error>
                </div>
            </div>

            <!-- Description -->
            <div class="col">
                <div class="md-form">

                    <input required type="text" id="materialapidefsFormDescription" class="form-control"
                        aria-describedby="materialapidefsFormDescriptionHelpBlock" mdbInput
                        formControlName="description" />

                    <label for="materialapidefsFormDescription">Description</label>
                    <mat-error
                        *ngIf="apidefsForm.controls['description'].hasError('required') && apidefsForm.controls.description.touched">
                        Description is required
                    </mat-error>

                    <mat-error
                        *ngIf="apidefsForm.controls['description'].hasError('maxLength') && apidefsForm.controls.description.touched">
                        maximum Length is 50
                    </mat-error>
                </div>
            </div>
        </div>

[... snip ...]

apidefs-disp.component.scss

.flex-disp-apidefs-container {
    display: flex;
    flex-direction: row;
    width: 100%;
    flex: auto;
}

.flex-disp-apidefs-list {
    display: flex;
    flex-direction: column; 
    //width:100%;
    flex:2;
}

.flex-disp-apidefs-form {
    display: flex;
    flex-direction: column; 
    //width: 100%;
    flex:4;
}

apidefs-list.component.scss

NOTHING

apidefs-form.component.scss

.text-center {
    width: 100%;
}

 .flex-apidefs-form{
    display:flex;
    width: 100%;
    padding: 30px;
    background-color: var(--accent-lighter-color);

 }

QUESTION: Is there a way to reduce the vertical space between two sets of input fields?

Any assistance, suggestions, or tips would be highly appreciated.

TIA

ETA I recently encountered an issue while trying to copy the code to Stackblitz (seems like it's related to a paid product - unsure if it should be included in StackBlitz).

Looking for solutions to address this problem...

Answer №1

I made a change to the CSS by switching the display property from 'flex' to 'grid'. This adjustment proved to be more user-friendly as it eliminated the need to define row and col repeatedly. Additionally, I discovered that the class md-form contained unnecessary padding which was affecting the layout (similar to a previous issue I encountered with the html p tag). To address this, I implemented the following:

.grid-apidefs-form .md-form {
    margin: 0em;
    height: 4em;
}

This code effectively reset the margin to 0 and set a new height of 4em for the element.

As a result, all functionalities are now operating correctly.

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

Issue with a Bootstrap panel displaying incorrect border formatting

I am currently working with Angular UI Bootstrap and facing an issue with an accordion component. Everything works perfectly fine in the development environment with the full version of the Bootstrap Cerulean file. However, when I minify the CSS file for p ...

What is the best way to align text in the middle on smaller devices like phones and iPads?

I have been working on a login screen and encountered a problem with the layout on smaller devices. Despite centering all the content perfectly on my computer's browser, when I inspect it using developer tools for smaller devices, everything shifts to ...

Resolved issue with fixed div flickering upon clicking link on Phonegap platform, leveraging Bootstrap

Upon attempting to click a link positioned at the bottom of the screen within a colored div using position:fixed;, I notice that the page momentarily flashes white before displaying the "new" page. Removing the fixed positioning allows the new page to load ...

Solution for repairing the display location button on Android within a React Native Map

I am facing an issue with the Location Button in my React Native Maps app. When the app is opened for the first time and the map is rendered, the button disappears. However, if I close the app but leave it running in the background, upon reopening the app, ...

Issue with displaying pictures in Ionic 2 Native Camera

As mentioned in the title, I am facing an issue where the picture is not displayed after taking a photo using the camera native function. I am attempting this on Android 5.0. Please let me know if you require any additional information. Here is the code ...

Restoring list item to standard CSS styling

I am having trouble with the alignment of my links. They are currently displayed in a horizontal manner instead of vertically like this: First link Second link Third link The current layout shows the links next to each other as follows: Firs ...

Adjust the color of the chosen <li> item to a different shade

I want to change the text color of the "Sale" item, but not a phone number using only CSS. Unfortunately, I am unable to modify the HTML code. https://i.stack.imgur.com/PPnna.png .menu.left a:first-child { background: yellow; color: red; } https ...

Designing websites using elements that float to the right in a responsive manner

Responsive design often uses percentage width and absolute positioning to adjust to different screen sizes on various devices. What if we explore the use of the float right CSS style, which is not as commonly used but offers high cross-browser compatibilit ...

Allow users to upload .docx and .xlsx file types with an input field of

I'm currently working on a file upload feature that requires checking for allowed file extensions. The two file extensions allowed are .docx and .xlsx. I've noticed that when I try to log the file extension using console.log, it doesn't prin ...

Step-by-step guide on arranging/placing/styling two div elements next to each other

I'm facing an issue with my CSS and HTML. I can't seem to get the 2 footer items to display on the same line. Is there a problem with how I've structured my divs and styles? Any suggestions for improving the code are greatly appreciated. I& ...

Databinding with AngularJS inside pre tags

Attempting to demonstrate databinding in a code snippet, but it keeps evaluating within the pre tag! Even when using { and }, it still evaluates. It's almost comical how such a simple issue is proving difficult to find an answer for online. ...

When attempting to import css-animator in Angular2/Typescript, a 404 error is displayed, indicating that the

Recently, I delved into the world of Angular2 and decided to experiment with some animations using css-animator package.json "dependencies": { "@angular/common": "2.0.0-rc.3", "@angular/compiler": "2.0.0-rc.3", "@angular/core": "2.0.0-rc.3", ...

Combining two elements in Angular 2

I am looking to find the intersection of two objects. My goal is to compare these objects and if they have matching values on corresponding keys, then I want to add them to a new object. obj1 = { "Projects": [ "test" ], "Companies": [ "facebook", "google ...

Personalized prefix for Angular and WebStorm components

After starting a project in Angular with Visual Studio Code a few months ago, I decided to switch to WebStorm and upgraded the project to Angular 4.0 today. Although my project is running smoothly without any errors, I encountered an issue in WebStorm: ...

Positioning a div to the right of another div within a container (box)

I'm currently trying to line up two divs alongside each other within a box. Using angularJS, I am dynamically generating input boxes and looking to include an image for the delete option next to each input box. Despite using "display: inline-block", I ...

Why is it not achievable to dynamically update the HTML DOM structure while `<!DOCTYPE html>` is specified?

The following HTML code is causing an issue: <!DOCTYPE html> <html> <head> <title>Clear a Timer</title> <meta charset="utf-8" /> <script> var theTimer, xPosition = 0, theImage; functio ...

The attempt to unserializing the configuration schema in Yii2 was unsuccessful

My brain feels scrambled... I am attempting to insert an image in HTML within Yii2. I retrieve it from the database and place it into the view file, but when I try to display it using HTML tags, an error is thrown. However, the image is being added perf ...

Position the final offspring adjacent to the one that came before it using Flexbox

I am trying to figure out how to position the last child (CVV) next to the previous one (Expiry), so they are on the same row: .form-col-1--cc { display: flex; flex: 30%; flex-direction: column; text-align: right; align-items: flex-end; } < ...

The program experienced an issue with TypeError: Attempting to access properties of an undefined variable ('_id')

I am attempting to show a data entry (with a unique id) in Angular, but I'm encountering the following error: ERROR TypeError: Cannot read properties of undefined (reading '_id') The service for retrieving the specific id is defined as: g ...

Ways to eliminate gaps between div elements with CSS

I am currently working on a webpage that consists of one main div housing two inner divs (left_menu and content), along with an additional footer div outside the main container. When viewing the page, there seems to be a noticeable gap between the footer ...