Best practices for styling column headers in HTML tables

Developing a web application using Angular Material has been my ongoing project. I have created an md-list with 7 columns to display different values. My goal is to add a header to each column to identify its corresponding value. While I have the headers ready, I am struggling to format them correctly. I came across a solution on Stack Overflow, which suggests using   or   in HTML to insert spaces.

I'm hesitant about using so many spaces for formatting. Do you have any suggestions for organizing the row headers above their respective columns more efficiently?

Thank you in anticipation of your advice.

Here's what I've attempted:


        <div layout="column">
            <md-content class="md-padding" layout-padding>
              <div class="md-list-column-headers" layout="row" flex="100">
                <h4><strong> User: &nbsp;&nbsp;&nbsp;&nbsp;</strong></h4>
                <h4><strong> Title: &nbsp;&nbsp;&nbsp;&nbsp;</strong></h4>
                <h4><strong> Description: &nbsp;&nbsp;&nbsp;&nbsp;</strong></h4>
                <h4><strong> Rating: &nbsp;&nbsp;&nbsp;&nbsp;</strong></h4>
                <h4><strong> Course: &nbsp;&nbsp;&nbsp;&nbsp;</strong></h4>
                <h4><strong> Date: &nbsp;&nbsp;&nbsp;&nbsp;</strong></h4>
              </div>
              <md-list flex >
                <md-list-item class="md-2-line"  ng-href="{{item.url}}" target="_blank" ng-repeat="item in pagedItems[currentPage] | orderBy:sortingOrder:reverse">
                  <div class="md-list-item-text" layout="column" flex="5">
                    <h4>{{$index + 1}}</h4>
                  </div>
                  <div class="md-list-item-text" layout="column" flex="10">
                    <span></span>
                    <h4>name</h4>
                    <md-divider></md-divider>
                  </div>
                  <div class="md-list-item-text" layout="column" flex="20">
                    <h4>{{item.title}}</h4>
                    <md-divider></md-divider>
                  </div>
                  <div class="md-list-item-text" layout="column" flex="10">
                    <h4>{{item.description}}</h4>
                    <md-divider></md-divider>
                  </div>
                  <div class="md-list-item-text" layout="column" flex="10">
                    <h4>{{item.description}}</h4>
                    <md-divider></md-divider>
                  </div>
                  <div class="md-list-item-text" layout="column" flex="5">
                    <h4>{{item.score}}</h4>
                    <md-divider></md-divider>
                  </div>
                  <div class="md-list-item-text" layout="column" flex="10">
                    <h4>{{item.course}}</h4>
                    <md-divider></md-divider>
                  </div>
                  <div class="md-list-item-text" layout="column" flex="15">
                    <h4>{{item.timestamp}}</h4>
                    <md-divider></md-divider>
                  </div>
                </md-list-item>
              </md-list>
            </md-content>
          </div>

Check out this image for formatting column headers

Answer №1

Apply the same flex values to the header columns as you did on each row's column. Instead of attempting to transform an md-list into a table, consider using a component created specifically for this purpose. I faced performance issues in IE and discovered that md-list was one of the causes. You may want to explore alternatives like: https://github.com/daniel-nagy/md-data-table

Alternatively, search for angular material table online for more options.

Answer №2

Experiment with adding a table header within a list item by utilizing the layout="row" attribute.

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

Obtain the following image with every click

I have a div with images inside. I created two arrows (previous, next) within a larger div using the src of one of the images as the background URL for each arrow. My goal is to make the next arrow change the large image to the src of the following image w ...

Modify MUI's ListItemText component by targeting a specific span to implement customized styles using the useStyle hook

It's quite perplexing that although this is a straightforward task in regular CSS, it must be accomplished through MUI's useStyles for some peculiar reason. Essentially, I possess a ListItem containing a ListItemText. It appears as follows: cons ...

Implementing gridlines on a webpage using HTML and JavaScript to mimic the grid layout found in Visual Studios

Currently, I have a grid snap function in place, however, I am looking to add light grey lines horizontally and vertically on my Designing application. The goal is to achieve a similar aesthetic to Visual Studios' form designing feature. Utilizing so ...

Retrieve a collection of paths using $routeProvider in Angular

I am working on an app that defines routes in the following manner: angular.module('myApp').config(['$routeProvider', function ($routeProvider) { 'use strict'; $routeProvider .when('/user-management', { ...

Show the flex items arranged horizontally

This template is generated dynamically by Django: <div class="center row"> <h3><span>The Core</span></h3> {% for member in core %} <a class="core_img " href="#"> <div class="img__overlay"> ...

Converting JSON data into a pandas dataframe using HTML

Has anyone had success converting the data found at this link: into a pandas dataframe? I am specifically interested in extracting the ''Q-code'' such as Concept ID (QCode) = medtop:01000000 and its associated Name(en-GB), for example ...

Javascript data table pagination and custom attributes resulting in unexpected truncation of strings

Currently, I have implemented an Ajax functionality in my template to receive a JSON response and dynamically populate a datatable with the elements from that JSON: $('.bicam_tests').click(function(){ $.ajax({ type: 'GET', ...

How to implement datepicker on multiple input fields

Below are the two input fields that have datepicker functionality: <div class="row"> <input type="text" class="form-control" datepicker-popup="{{format}}" ng-model="dt" is-open="opened" min="minDate" max="'2015-06-22&apos ...

Use an if statement in Angular to conditionally add a title attribute with an empty value to HTML

How can I conditionally add the title attribute to a div without creating another div and using ngIf? If the permission is true, I want to include a title in my div. Here's what my current div looks like: <div (click)="goToChangelog()&quo ...

"Using jQuery to dynamically change the src attribute of an iframe, the change persists even after

There's a strange issue bothering me. On a single page, I have a menu and an iframe. Whenever I click on a menu button, the jQuery code changes the src attribute of the iframe. Initially, when the page loads, the iframe is supposed to display "Home". ...

Enhance your website with a dynamic jQuery gallery featuring stunning zoom-in

I am currently working on a mobile website project and I'm in need of a gallery feature that allows users to zoom in on images and swipe through them using touch gestures. After some research, I haven't been able to find a suitable solution in j ...

Delivering HTML Email

I want to send an HTML email with images using Google's SMTP servers. Here is the HTML code with inline CSS that I have generated: <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type& ...

Exploring the Powerful $interval Built-in Service in AngularJS

Below is the code snippet: <!DOCTYPE html> <html ng-app="app14" ng-cloak> <head> <meta charset="UTF-8"> <title> Angular built-in services</title> <style> [ng\:cloak], [ ...

Setting the height and width to 100% causes the element to slightly protrude

After setting the height and width of a canvas to 100%, I noticed that instead of fitting the screen perfectly, it slightly exceeded the boundaries, causing a scroll bar to appear allowing me to scroll just a few pixels up, down, left, or right, even after ...

I'm struggling to make my div display inline

My div elements are not displaying inline, I'm thinking maybe I shouldn't use the nav and div structure like this. But starting over again seems like a lot of work. How can I fix this issue? Just so you know, I'm only on my 4th day of learn ...

Turning off and on CSS transitions to set the initial position

Is there a way in javascript to position divs with rotations without using transitions initially for an animation that will be triggered later by css transition? I have tried a codepen example which unfortunately does not work on the platform but works fin ...

Adding an AngularJS directive dynamically that utilizes a $http request for fetching data

Currently facing an intriguing issue, I am attempting to create something like this: input key 1 , input value 1 input key 2 , input value 2 < button to add more > < submit button > Essentially, a user can click submit and send a Get req ...

Accessing factory in controller using AngularJS

Currently, I am utilizing the following link to integrate requirejs with angularjs: https://github.com/StarterSquad/startersquad.github.com/tree/master/examples/angularjs-requirejs-2 My question is regarding how to use a service function that is defined ...

Angular: Radio button groups are not responding correctly when populated within a loop using ng-repeat

My goal is to populate multiple sets of radio buttons in a loop by combining the group name and index to ensure each set is uniquely grouped. However, I am facing an issue where only the last group in the loop has a checked radio button, while all other gr ...

Having difficulty navigating between Spring MVC and Angular Js components in my project

https://i.sstatic.net/Iovci.png I am currently facing an issue with my project structure. I received a "Failed to load resource: the server responded with a status of 404 ()" error message, indicating that ShowDetail.jsp is not found. Can anyone advise on ...