14

How can I add multiple inputs on same row? I have tried using bootstrap but for some reason it wont work. If you have some exemple to show me.

<form class="example-form">
  <mat-form-field class="example-full-width">
    <input matInput placeholder="First Name">
  </mat-form-field>

  <mat-form-field class="example-full-width">
    <input matInput placeholder="Last Name">
  </mat-form-field>
</form>
3
  • Please show some HTML and CSS... Commented Apr 24, 2018 at 11:00
  • @KelvinLai it is a simple code, I have added Commented Apr 24, 2018 at 11:07
  • I smell a rat in your CSS (example-full-width)! I just tried your example in my code and I saw both on the same line. Also, you could always have these components in a table with one row and two columns. Commented Apr 24, 2018 at 12:35

2 Answers 2

15

Angular Material's inputs are displaying in row by default (see stackblitz below), and may be you override this behavior somewhere in your project, I mean CSS rules. If you like Flexbox, you can use @angular/flex-layout, you can easily control how to display items: in row or in column, and this package is very common among Angular developers. Here is a simple demo with "default" behavior (without any additional rules) and 2 layout options: column and row:

STACKBLITZ

Sign up to request clarification or add additional context in comments.

5 Comments

I don't have any CSS, it's a new projet
@Rubyen Do your inputs looks like Material inputs? I mean, do they render properly (except that they are not in row)? And their default animation works?
They look like Material inputs, I have added flex-layout to my project and tried to used it, but it wont put on the same row. I took the code from demo.
@Rubyen, tell us, what the problem was)
well it was an css, that I forgot about, it was a width that was put to 100%, but the class was put on the input
4

You are probably looking at the css style display: block; Change whatever you are looking at to display: inline-block;

edit

Now that you showed some code. Your basic html is fine, it shows the inputs next to each other. So something is wrong inside your example-form or example-full-width classes.

1 Comment

I have changed to display:inline-block but it doesn't change

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.