Ways to align two divs side by side

My goal is to design a webform where users can enter the dates they want to take off from work. I have two div classes that I want to align horizontally and when the "Add Dates" button is clicked, another line should be added.

I attempted to place the two divs inside a larger div and set the style to inline.

<div class = "Leave" style="display: inline">
                    <h4>Select Leave Code</h4>
                    <mat-form-field>
                      <select matNativeControl required>
                        <option value="personal">Personal Leave</option>
                        <option value="vacation">Vacation Leave</option>
                        <option value="sick">Sick Leave</option>
                      </select>
                    </mat-form-field>
                    <div class = "Dates">
                            <mat-form-field>
                                    <input matInput [matDatepicker]="picker1" placeholder="From" [formControl]="date">
                                    <mat-datepicker-toggle matSuffix [for]="picker1"></mat-datepicker-toggle>
                                    <mat-datepicker #picker1></mat-datepicker>
                                  </mat-form-field>
                                  
                                  <mat-form-field>
                                    <input matInput [matDatepicker]="picker2" placeholder="To"
                                           [formControl]="serializedDate">
                                    <mat-datepicker-toggle matSuffix [for]="picker2"></mat-datepicker-toggle>
                                    <mat-datepicker #picker2></mat-datepicker>
                                  </mat-form-field>
                    </div>
            </div>

button

<div class = "adder">
                    <div class = "sub">
                            <button mat-raised-button color="primary">Add Dates+</button>
                        </div>
            </div>

I am attempting to attach a screenshot, but currently it appears like a pyramid. The Leave code dropdown is on top and the two calendar icons are on the next line side by side

View how it looks on my page

Answer №1

display: flex; Utilizing this CSS property will cause all child elements to become inline.

<div style="display:flex; flex-direction: row;">
   <div>1</div>
   <div>2</div>
</div

This serves as an illustration of inline child elements. For further information, please refer to the following link Flexbox Layout Guide

Answer №3

Could you elaborate on your request for "when the button labeled 'Add Dates' is clicked, I would like a new line to appear"?

Regardless, when attempting to display two objects inline, ensure that you include the style="display: inline" property on each element you wish to be shown inline. Therefore, consider adding the style="display: inline" property to the specified element.

I trust this information is beneficial to you.

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

Guide to implementing tooltips for disabled <li> elements in AngularJS

I have a list of items that are displayed using the following code: <li class="dropdown-item" data-toggle="tooltip" uib-tooltip="tooltip goes here" data-placement="left" data-ng-repeat="result in items.results.contextValues.rows " ...

SASS loop encountering issue when trying to adjust hsla lightness, error is due to $lightness value being treated as a string instead of a number for 'hsla'

I'm attempting to create a loop that gradually decreases the lightness value of hsla over a set number of iterations. However, when I execute the loop, I encounter an error stating $lightness: "96.77419" is not a number forhsla'`. Can someone ple ...

Filterable Select Dropdown in Angular Material

Currently, I am attempting to build a basic select list using the Angular Material List Module. However, I am encountering an issue when trying to integrate this with a filter. While I have managed to implement this functionality, I face difficulty in fil ...

Using HTML to dynamically alter a row's background color depending on its value

I have a table within an HTML page that I would like to color all rows in red when the first column reaches a specific value. After researching on StackOverflow, I found suggestions to add these two attributes (border-collapse and border-spacing) to my ta ...

I need to dynamically change the font color based on the data retrieved from the API

I am looking to dynamically change my font color. <div *ngIf="clientProfileModel.patientHealthScore[0].kidneyScoreStatusByColor==='Normal'" [ngStyle]="{color:'#ff5454'}" then *ngIf="clientProfileModel.pat ...

Choosing multiple lists in Angular 2 can be achieved through a simple process

I am looking to create a functionality where, upon clicking on multiple lists, the color changes from grey to pink. Clicking again will revert the color back to grey. How can I achieve this using class binding? Below is the code snippet I have tried with ...

Unlock the secrets of extracting video from a livestream and seamlessly transferring it to a local web server without the need

Hey there, I have this link: '' Although it's not a real link, entering it leads to a .m3u8 file for live video streaming. I attempted using this link in my Angular 6 app frontend, but encountered a cross-origin issue as the video is being ...

Adding space around images in JavaFX

Just a quick question. I'm wondering if there is a way to apply padding to an ImageView using CSS in JavaFX. I've attempted insets, padding, and other methods with no success. Alternatively, can the same effect be achieved with a Text Object? ...

OpenStreetMap is failing to display the full map within the designated div

Here is the code snippet for displaying a map when clicking on a Span text, but not showing it in full: var latitude = document.querySelector('#lati').value; var longitude = document.querySelector('#longi').value; var open_address = doc ...

Angular experiencing timeout due to Spring Boot service offline

When my Angular frontend tries to make a POST http request but the Spring Boot backend service is not running, I see the following error in the Chrome console after a few seconds: POST https://localhost:8080/report/data net::ERR_TIMED_OUT I added an erro ...

What is the process to extract the displayed font using JavaScript?

One interesting feature of Google Chrome is that it displays the rendered font in DevTools. For instance, when you have the CSS code: font-family: Montserrat, Helvetica, sans-serif; and the Montserrat font is not available or disabled, Chrome will indic ...

Navigating through error messages in NextJs 14 can be tricky, especially when faced with the dreaded "ReferenceError: document not defined" or "prerendering error". It's vital to pinpoint exactly which page

When attempting to run the build on my Next.js application, I encountered an error message that is not very informative given the number of files/pages in my project. How can I pinpoint the exact location of this error and determine the root cause? The pro ...

How can I place an icon on a specific location in a Highcharts map?

I am currently utilizing Highcharts to showcase maps within my application. I am aiming to achieve two specific functionalities: 1) Upon clicking on any area, I want that area to be highlighted in red {completed} 2) Upon clicking on any area, I intend f ...

Choose the Angular 2 option

I am having an issue with the select option in my code. The person's gender property is assigned 'M' for male, but I need to allow users to change it to 'F' for female. Here is the HTML code snippet: <span > <span &g ...

Finding and choosing a date from an ng-model datepicker using Selenium Webdriver - a guide

I am encountering an issue where I can open the date picker pop-up calendar with a click, but I cannot select a specific date from it. This is due to the input field being read-only, which means that any input provided through sendkeys or JavascriptExecuto ...

Having trouble with component loading in Angular 2 rc5?

I'm encountering an issue with the webpack prod build where components are not loading, and strangely there are no errors. The dev build, on the other hand, works perfectly fine. Here's a snippet of the code: freight-list.component.ts @Compone ...

Exploring the incorporation of asynchronous functionality within Angular Material's Matstepper component

Currently, I am implementing the Stepper component from Angular Material2 in conjunction with Angular4. Component1 <mat-horizontal-stepper #stepper> <mat-step></mat-step> <mat-step></mat-step> </mat-horizontal-stepper> ...

The function Observable.of is not available when importing correctly

I encountered an issue with importing the "of" method for observable in Angular 6. Even after setting up a new project and updating all packages, the error persists. To troubleshoot, I created a small project to identify the problem. Here is the service: ...

Is there a background effect when tapped?

Have you noticed the background effect that appears when tapping on certain <a> elements on a webpage? Some have a visual feedback, while others do not. This phenomenon occurs on Chrome for Android as a quick flash of blueish color for a brief moment ...

What is the process for establishing a paragraph class within a div using the paragraph style?

My content is within a main div called "wrapper-landing" and I have created a paragraph style for all <p> tags using #wrapper-landing p. However, when I added another class to my <p> tag, it did not apply the style. It only applied the style of ...