Effortlessly Aligning Asp MVC Table Elements in the Center

My current issue involves a list of objects displayed in a table view created with aspmvc. The problem is that all the elements are not aligned properly, and I want them to be centered within the table. Here's what it looks like: https://i.sstatic.net/oUu5M.png

The code I'm using seems pretty generic, as it's mostly generated by default.

<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.m_EmailAddress)
        </th>
        (...)
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.m_EmailAddress)
        </td>
       (...)
    </tr>

I've attempted to align everything to the center with this code:

<table class = "table" align = "center">

However, it didn't work out as expected.

If anyone has suggestions or can point me in the right direction, I would greatly appreciate it. Thank you!

Edit:

I also tried using <th text-align: center>, but the alignment still appears off to the left. Here's how it currently looks: https://i.sstatic.net/xtDZm.png

Answer №1

To easily style the entire table, simply add this code:

.table th, .table td {
    text-align: center;
}

You can insert this directly into your page markup, right before the <table> tag:

<style type="text/css">
    .table th, .table td {
        text-align: center;
    }
</style>
<table class="table">

Alternatively, you can place this code in a site CSS file that your layout or view is referencing.

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

Exploring the functionality of buttons within jQuery Impromptu

My current project involves creating a survey composition tool. The main focus is on having a preview button that displays the values inputted by the user. <!doctype html> <html> <head> &l ...

When an option is selected in one dropdown, a list is dynamically populated in another dropdown. However, the entire column then displays the selected row's options in a table format

https://i.stack.imgur.com/q7tMT.png Upon selecting an option from a dropdown within a table row, I make a call to an API to fetch a list of strings into another dropdown field for that specific row. However, the entire column is being populated with that r ...

"Returning undefined: The outcome of using jQuery's .html() method on

I am having an issue with the JavaScript function I have created to load content from another URL into the current document. For some reason, both contentHtml and menuHtml variables are showing as undefined. Can someone please help me identify where I we ...

There is a clash between two functionalities in jQuery

Here on this website, I am utilizing two instances of jQuery - one for an "anything slider" and another for a toggle that hides and shows content. When I remove the link to jQuery for the toggle feature, the slider works fine but the toggle does not. Here ...

Retrieve the value of a TextBox and display it as the title of a Tool

Hello there, I am currently learning front-end technologies and have a question. I would like to retrieve the value of a TextBox and display it in a Tool-tip. The code for the TextBox has a maximum length of 30 characters, but the area of the TextBox is no ...

Verifying that phone numbers and email addresses are accurate prior to submitting the form

As a PHP newcomer, I apologize if my question appears somewhat naive. Currently, I am working on a contact form that is functioning well, but I need to implement validation for two specific fields: the phone number and the email address. For the phone numb ...

In Angular/Typescript, dynamically add a class to a `td` element when it is clicked. Toggle the class on and off

My problem arises when trying to individually control the arrow icons for each column in my COVID-19 data table. By using Angular methods, I aim to show ascending and descending arrows upon sorting but run into the challenge of changing arrows across all c ...

Encountered a problem when attempting to access an element on a PHP page using

My javascript code is supposed to retrieve information from a specific URL (song.php) which contains the name of a song. However, there seems to be an issue as the javascript is not extracting the required data. Below is the HTML element and javascript fo ...

What is the best way to eliminate the border in IE edge that surrounds special characters?

Here is the current appearance of the cross button in IE/Edge: https://i.sstatic.net/JZ37V.png And here is how it is supposed to look: https://i.sstatic.net/Uqafg.png Upon inspecting the CSS, it reveals that the #10006 html character has a color code o ...

What is the best approach for maximizing user experience: setting a maximum screen width or allowing for auto-width?

I manage a blog with responsive design that adjusts to the width of the screen. The majority of our blog posts consist of lengthy content, often reaching over 1000 words, along with user comments. My main concern is about the reading comfort and usability ...

Seeking assistance in initiating/awakening the API following a restart of the Application Pool or the IIS

I have developed a WebAPI using the C# language and it is hosted on a Windows Server Datacenter 2019. The requirement for the API is to always be running and ready, without being disposed of. If I stop the Application Pool and then start it again, the AP ...

Material-UI icons refusing to show up on the display

I've been working on creating a sidebar component and importing various icons to enhance the UI, but for some reason they are not displaying on the screen. I even tried other suggested solutions without success. <SidebarOption Icon = {InsertComment ...

Set Bootstrap column size to match a particular column

I am currently using BootStrap 4 and I am attempting to make a column's height equal to another column. Below is the code snippet I am working with: <div class="container" style="overflow:hidden"> <div class="row" style="overflow:hidden" ...

Transmit updated value to masterpage upon selection alteration

In my current project using ASP.NET, I have a MasterPage that includes a navigation bar with different options. One of the options leads to another page where the company now requires me to pass a parameter through the link. After some research, I managed ...

Linking jQuery UI tabs to tabs on a different pageWould you like assistance

I am facing a challenge that I need help with. For a school project, I have to create 8 pages of HTML, each with a template and a menu. The menu consists of tabs that are supposed to link to separate pages when clicked. However, the issue is that when I cl ...

Recording the mouse click action following the turning over of the tile

Greetings! I have successfully implemented a zoom and flip feature on my tile. My tile now showcases two different views - the initial view displays an image, while the back view shows text. However, I am encountering an issue where multiple alert boxes ...

Showing data from the POST request in a dialog box

Greetings to all! I am in the process of building a webpage to test my API. The goal is to send a form to my nodejs backend and receive a JSON response back. So far, sending the request is functioning properly and I can track its progress on my VPS conso ...

Initiate an Elementor popup upon form submission (After submit event) using Contact Form 7 in WordPress

I have incorporated Elementor popups and contact form 7 into my WordPress website. Currently, my goal is to activate the Elementor popup after the contact form 7 form has been submitted. Below is what I have tried so far, and there have been no console er ...

The code snippet for the carousel in Bootstrap does not function correctly in VSCode, yet it operates effectively on codeply.com

code: <div class = "carousel-inner"> <div class = "carousel-item active" style = "background-color:red" > <h2>I don't have to sniff other dogs anymore for love. Thanks to TinDog, ...

Repairing the Left-sided Popup Leaflet

Can someone help me with fixing the positioning of the Popup to the left of the map? Currently, it does not stay aligned to the left edge when moving the map. I tried using position: fixed in my styling, and while everything looks good when zooming, it br ...