0

I have this html page:

<div class="panel panel-default">
    <div class="panel-heading">
        <h1>Usuarios</h1>
    </div>
    <div class="panel-body">
        <table class="table table-striped table-bordered">
            <thead>
                <tr>
                    <th>Nome</th>
                    <th>Telefone</th>
                    <th>Email</th>
                    <th>Ações</th>
                </tr>
            </thead>
            <tbody>
                <tr *ngFor="let usuario of usuarios | async">
                    <td>{{usuario.nome}}</td>
                    <td>{{usuario.telefone}}</td>
                    <td>{{usuario.email}}</td>
                    <td><button (click)="deleteUsuario(usuario.id)" class="btn btn-danger">Delete</button>
                    <button (click)="updateUsuario(usuario.id)" class="btn btn-info" style="margin-left: 10px">Update</button></td>
                </tr>
            </tbody>
        </table>
    </div>
</div>

The width is following the navbar, so it's being stretched all the screen:

enter image description here

How can I reduce it to the center of the screen like a have a margin before and after the form?

I want it to be like this:

enter image description here

2
  • Can you explain in more detail what you actually want? Commented Dec 11, 2019 at 11:48
  • 1
    did you try margin:0 auto? Commented Dec 11, 2019 at 11:49

2 Answers 2

1

Looking at your screenshot I guess you are using Materialize CSS:

Try to the form code within below code:

<div class="container">
   <div class="col s12">
      <div class="panel panel-default">
    <div class="panel-heading">
        <h1>Usuarios</h1>
    </div>
    <div class="panel-body">
        <table class="table table-striped table-bordered">
            <thead>
                <tr>
                    <th>Nome</th>
                    <th>Telefone</th>
                    <th>Email</th>
                    <th>Ações</th>
                </tr>
            </thead>
            <tbody>
                <tr *ngFor="let usuario of usuarios | async">
                    <td>{{usuario.nome}}</td>
                    <td>{{usuario.telefone}}</td>
                    <td>{{usuario.email}}</td>
                    <td><button (click)="deleteUsuario(usuario.id)" class="btn btn-danger">Delete</button>
                    <button (click)="updateUsuario(usuario.id)" class="btn btn-info" style="margin-left: 10px">Update</button></td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
   </div>
</div>
Sign up to request clarification or add additional context in comments.

Comments

1

Just add this style code:

form {
   max-width: 900px;
   margin-left: auto;
   margin-right: auto
}

5 Comments

<form (ngSubmit)="onSubmit()" style="max-width: 900px;margin-left:auto;margin-right: auto" >
as i wrote, an inline style in your form tag. or if you don't like that you should create a separete .css file then link to that
if this helped you, i'll appreciate marking my answer as best answer
I edited again, i had pasted the code for the form, but the screen is actually the list of users. But tryied your answer and the form was still in the left
Oh my God! i realized the issue. put that code for parent div <div class="panel panel-default" style="max-width: 900px;margin-left:auto;margin-right: auto" >

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.