Tips for minimizing the width of a form in CSS/HTML

I created an HTML page with the following code:

<div class="panel panel-default">
    <div class="panel-heading">
        <h1>Users</h1>
    </div>
    <div class="panel-body">
        <table class="table table-striped table-bordered">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Phone</th>
                    <th>Email</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody>
                <tr *ngFor="let user of users | async">
                    <td>{{user.name}}</td>
                    <td>{{user.phone}}</td>
                    <td>{{user.email}}</td>
                    <td><button (click)="deleteUser(user.id)" class="btn btn-danger">Delete</button>
                    <button (click)="updateUser(user.id)" class="btn btn-info" style="margin-left: 10px">Update</button></td>
                </tr>
            </tbody>
        </table>
    </div>
</div>

The width is currently stretching out to fill the screen:

https://i.sstatic.net/41Tvp.png

How can I center it on the screen with some margin before and after the form?

I would like it to look like this:

https://i.sstatic.net/J6iLx.png

Answer №1

Upon analyzing your screenshot, it appears that you are utilizing Materialize CSS:

Consider integrating the form code within the following structure:

<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>

Answer №2

To implement this style modification, simply include the following CSS snippet:

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

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

Refining Content without the Need for a Submit Button in Django

To filter objects, I currently have to choose an option from the dropdown box and then click the submit button. However, I want the filtering process to happen immediately after selecting an alternative from the dropdown menu, without having to click the ...

Tips for removing a checkbox and customizing a label's style when the label wraps around the checkbox input

Hello, I'm an advanced beginner so I appreciate your patience:) I've had success removing checkboxes and styling their labels when the for="" attribute is present. However, I'm facing a challenge with a form where the labels wrap the input ...

Targeting HTML tags, styling names, and class names using CSS

In the markup below, I am trying to target three specific points using CSS. img style*=right class=media-element I attempted to use the code below, which did not work: img[style*="right"][class="media-element"] {margin-left:10px;} However, selecting t ...

Guide to declaring variables using jQuery

Currently tackling a school project, I stumbled upon some online example solutions and managed to decipher most of the code. However, there is one line that has me puzzled. var $newTweet = $('<div class=tweet></div>'); My assumption ...

Using JQuery's onChange event triggers actions based on the current values of input fields. However, in some

I am currently tackling an issue with a module that is designed to automatically select the only valid value from a Multi- or Single selection field when there is just one valid option and an empty choice available. Initially, everything was working smoot ...

Article with content surpassing the boundary of its parent container

I'm struggling to contain text within the parent's div as it keeps overflowing. I attempted using element.style { text-overflow: ellipsis; overflow: hidden; } but unfortunately, it didn't work. Take a look here at my JSFiddle link. It ...

Choose several identifiers that possess strikingly similar titles

I am dealing with a form that is dynamically generated by a third-party provider and unfortunately I am unable to modify it... However, I am looking for a solution to select all IDs that begin with the same string, such as: easi_fielddiv_LastName, easi_fi ...

Implementing a line break within a JavaScript function specifically designed for formatting images

As I am not a javascript developer, the code I have been given for debugging is somewhat challenging. The issue at hand involves an iOS module where a .js CSS file has been set up and images are loading improperly, resulting in the need for horizontal scro ...

Unable to connect to a style sheet

I'm in the process of developing a web application and I'm facing an issue with linking a stylesheet to my app. Check out my code below: <html> <head> <title>Bubble</title> </head> <link rel=" ...

Using ng-options with the Add New feature is not compatible with the select statement

Hello everyone, I have some JSON values that look like this: [{"Employee":{"Emp_id":"EF00001","First_name":"Aruna","Last_name":"Jayalath"}}] Unfortunately, I am having trouble retrieving the values within the select statement when running this function i ...

Include the HTML 5 doctype declaration in an XDocument in the .NET framework

When generating a doctype for an System.Xml.Linq.XDocument like shown below: doc.AddFirst(new XDocumentType("html", null, null, null)); The output XML file begins with: <!DOCTYPE html > There seems to be an extra space before the closing angle br ...

What method can I use to adjust the font style when it overlays an image?

Sorry if this is a bit unclear, but I'm trying to figure out how to change only a section of my font when it overlaps with an image while scrolling. If you visit this example website, you'll see what I'm referring to: For a visual represen ...

Tips for implementing a watermark background image that appears in each section of a single-page website

Currently, I am exploring HTML, CSS, and Bootstrap and facing a particular issue. I am attempting to add a logo to a website as a background. I have already discovered how to do this by following the instructions here. This website is comprised of a sing ...

Turn off the background when the automatic popup box appears

I have implemented a popup box that automatically appears after 5 seconds when the site is loaded. However, if I click outside of the popup box, it closes. I want to disable the background when the popup box is displayed. If I remove the two lines of code ...

When the height expands, the div spills over and engulfs the following div

I am facing an issue with my divs on a page that have a "see more details" link. When clicked, the div expands and should fit the height of the parent div seamlessly. However, currently, each div overflows onto the next parent div until I scroll, at which ...

What happens in the React tutorial when the clear fix is commented out and the appearance does not change?

Currently, I am working through the React tutorial and have encountered a question regarding their starter code: class Square extends React.Component { render() { return ( <button className="square"> {/* TODO */} </butto ...

Understanding CSS classes in ReactJS Material UI componentsJust wanted to clarify some things

When it comes to styling Material UI components, the recommended approach is to utilize their useStyles function. Here's an example: const useStyles = makeStyles(theme => ({ root: { marginTop: '15px', display: 'f ...

Prevent the left border from displaying on a link that wraps to a new line

Excuse me, I am facing an issue with a pipe separator in my subnav bar between links. The problem is that the first link on a new line retains the left-border that should be disabled. How can I prevent this border from appearing on the first link of a new ...

Prevent the underlining of the :before content of a link from being affected by a rule applied to the link

I have a hyperlink that becomes underlined when hovered over. I want to add a > symbol before the link, but I don't want it to be underlined when the link is hovered. Here's the code I'm using: .box.blueb a { color: #0098aa; } .box.blueb ...

How can I consistently position a dialog box (tooltip) on top of a JQuery UI modal Dialog?

Utilizing CSS and Javascript to display tooltips upon mouseover for various inputs has been effective in most cases, however I am encountering an issue with inputs within a Jquery UI Dialog modal. The tooltips appear correctly in front of the dialog when i ...