Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add spacing between input elements

How can I add spacing between input elements that has flex-direction: row. I'm using components from the angular-material library. Below screenshot with a highlighted inputs that must have spacing between them

enter image description here

HTML

<form class="form-container">
    <mat-form-field class="full-width">
        <mat-label>First name *</mat-label>
        <input type="text" name="firstName" matInput placeholder="First name" value="">
    </mat-form-field>

    <mat-form-field class="full-width">
        <mat-label>Last name *</mat-label>
        <input type="text" name="lastName" matInput placeholder="Last name" value="">
    </mat-form-field>

    <div class="date-of-birth">
        <mat-form-field>
            <mat-label>Day</mat-label>
            <input type="number" name="day" matInput placeholder="Day" value="">
        </mat-form-field>

        <mat-form-field>
            <mat-label>Month</mat-label>
            <input type="number" name="month" matInput placeholder="Month" value="">
        </mat-form-field>

        <mat-form-field>
            <mat-label>Year</mat-label>
            <input type="number" name="year" matInput placeholder="Year" value="">
        </mat-form-field>

    </div>

</form>

CSS

.form-container {
  min-width: 150px;
  max-width: 500px;
  width: 100%;
  margin: 0 auto;
}

.full-width {
  width: 100%;
}

.date-of-birth {
  display: flex;
  flex-direction: row;
}
like image 837
Andrew Avatar asked Jun 24 '26 20:06

Andrew


1 Answers

Adding gap in .date-of-birth will solve your issue:

<form class="form-container">
    <mat-form-field class="full-width">
        <mat-label>First name *</mat-label>
        <input type="text" name="firstName" matInput placeholder="First name" value="">
    </mat-form-field>

    <mat-form-field class="full-width">
        <mat-label>Last name *</mat-label>
        <input type="text" name="lastName" matInput placeholder="Last name" value="">
    </mat-form-field>

    <div class="date-of-birth">
        <mat-form-field>
            <mat-label>Day</mat-label>
            <input type="number" name="day" matInput placeholder="Day" value="">
        </mat-form-field>

        <mat-form-field>
            <mat-label>Month</mat-label>
            <input type="number" name="month" matInput placeholder="Month" value="">
        </mat-form-field>

        <mat-form-field>
            <mat-label>Year</mat-label>
            <input type="number" name="year" matInput placeholder="Year" value="">
        </mat-form-field>

    </div>

</form>

CSS

.form-container {
  min-width: 150px;
  max-width: 500px;
  width: 100%;
  margin: 0 auto;
}

.full-width {
  width: 100%;
}

.date-of-birth {
  display: flex;
  flex-direction: row;
  gap: 20px;
}
like image 53
Ahmad Habib Avatar answered Jun 27 '26 13:06

Ahmad Habib



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!