trouble with the layout of the table

Could you assist me in improving the design to enhance data clarity? Your help would be greatly appreciated. Thank you for your anticipated response.

CSS File:

  table-layout: fixed;
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  overflow: hidden;

  }  

HTML File:

         <div class="col-md-12">
           <div class="table-wrap">
             <table class="table table-striped" >
               <thead>
                 <tr>
                   <th class="odd" colspan="4">id</th>
                   <th class="odd" colspan="4">name</th>

                   <th *ngIf="isAdmin()" class="odd" colspan="4"> password</th>
                   <th class="odd" colspan="4">role</th>
                   <th class="odd" colspan="4"class="corner wideRow">email</th>

                 </tr>
               </thead>
               <tbody>

                 <tr *ngFor="let el of users | paginate: { itemsPerPage: 2, currentPage: p }">


                 <th class="odd" colspan="4"  ></th>
                 <td class="odd" colspan="4" >{{el.id}} </td>
                             <td class="odd" colspan="4" >{{el.username}}</td>

                             <td *ngIf="isAdmin()" class="odd" colspan="4">{{el.password}}</td>
                 <td class="odd" colspan="4" >{{el.role}}</td>
                             <td class="odd" colspan="4" >{{el.email}}</td>



                           <td  class="odd" colspan="4"> 
                 <tr>
                   <a *ngIf="isAdmin()"
                   class="btn btn-danger" (click) = "deleteUser(el.id)" >Delete</a>

                   <a *ngIf="isAdmin()" class="btn btn-success" data-original-title="Edit">Edit</a> 

                                </tr>       
 </td>
                          
                           
                         </tbody>
                       </table>
             </div>
             </div>

       </div>
       <pagination-controls (pageChange)="p = $event"></pagination-controls>

The current result is not clear and I am uncertain how to improve it. https://i.sstatic.net/LBJF1.png

I attempted to add this to the CSS but did not achieve the desired outcome:

table td { word-break: break-all;

}** the result result 2

Answer №1

1.) It is illogical to have colspan="4" in every cell.

2.) The presence of an empty th element at the beginning of the tbody rows is causing the alignment issue you mentioned. Remove it so that IDs align under the "id" header, names under the "name" header, etc.

3.) Add an extra th cell at the end of the header row to match the number of cells in the rows below, especially those containing nested tables with buttons.

.table-striped {
  width: 100%;
  border-collapse: collapse;
}

table td {
  border: 1px solid #ddd;
  word-break: break-all;
}
<table class="table table-striped">
  <thead>
    <tr>
      <th class="odd">id</th>
      <th class="odd">name</th>
      <th *ngIf="isAdmin()" class="odd"> password</th>
      <th class="odd">role</th>
      <th class="odd">email</th>
      <th class="odd"></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr *ngFor="let el of users | paginate: { itemsPerPage: 2, currentPage: p }">
      <td class="odd">{{el.id}} </td>
      <td class="odd">{{el.username}}</td>
      <td *ngIf="isAdmin()" class="odd">{{el.password}}</td>
      <td class="odd">{{el.role}}</td>
      <td class="odd">{{el.email}}</td>
      <td>
        <table>
          <tr>
            <td>
              <a *ngIf="isAdmin()" class="btn btn-danger" (click)="deleteUser(el.id)">Delete</a>
            </td>
            <td>
              <a *ngIf="isAdmin()" class="btn btn-success" data-original-title="Edit">Edit</a>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </tbody>
</table>

Answer №2

Include this CSS code

table td {
    word-break: break-all;
}

Use the following corrected HTML code ensuring that your header and body columns are equal.

<div class="col-md-12">
    <div class="table-wrap">
        <table class="table table-striped">
            <thead>
                <tr>
                    <th class="odd" colspan="4"&rt;id</th>
                    <th class="odd" colspan="4"&rt;name</th&rt;
                    <th *ngIf="isAdmin()" class="odd" colspan="4"&rt; password</th&rt;
                    <th class="odd" colspan="4"&rt;role</th&rt;
                    <th class="odd" colspan="4"&rt;email</th&rt;
                    <th class="odd" colspan="4"&rt;</th&rt;
                </tr&rt;
            </thead&rt;
            <tbody&rt;
                <tr *ngFor="let el of users | paginate: { itemsPerPage: 2, currentPage: p }"&rt;
                    <td class="odd" colspan="4"&rt;{{el.id}} </td&rt;
                    <td class="odd" colspan="4"&rt;{{el.username}}</td&rt;
                    <td *ngIf="isAdmin()" class="odd" colspan="4"&rt;{{el.password}}</td&rt;
                    <td class="odd" colspan="4"&rt;{{el.role}}</td&rt;
                    <td class="odd" colspan="4"&rt;{{el.email}}</td&rt;
                    <td&rt;
                        <table&rt;
                            <tr&rt;
                                <td&rt;
                                    <a *ngIf="isAdmin()" class="btn btn-danger" (click)="deleteUser(el.id)"&rt;Delete</a&rt;
                                </td&rt;
                                <td&rt;
                                    <a *ngIf="isAdmin()" class="btn btn-success" data-original-title="Edit"&rt;Edit</a&rt;
                                </td&rt;
                            </tr&rt;
                        </table&rt;
                    </td&rt;
                </tr&rt;
            </tbody&rt;
        </table&rt;
    </div&rt;
</div&rt;

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

Ionic app encountering issues with Facebook OAuth login functionality

Currently, I am implementing Facebook Auth for my Ionic app by using the Firebase module. Despite setting up the firebase module correctly initially, I keep encountering an error during the login process. It should be noted that the login function worked p ...

Show the HTML page returned by the server on the client side

Hey there! I've come across a PHP code snippet that sends back an HTML file as a response. This PHP code makes use of the include method to send the file. When I'm on the client side, I'm employing AJAX. Upon typing console.log(data) (with ...

What is the best way to have three divs displayed in a row - either all inline or all block, without having two displayed inline and one displayed

I am facing an issue with a set of three inline divs that need to be displayed either in a row or in a column if they do not fit within their container width. In cases where the container is too narrow for them to fit in one row, but not narrow enough to c ...

Firefox not responding to input select dropdown selection

When creating a jQuery submenu box in Firefox, I encountered an issue with the input select dropdown. While it functions properly in Google Chrome, the select box behaves erratically in Firefox. When attempting to choose an option from the select box, such ...

Unable to delete the margin of Material-ui TextField

Having trouble removing the padding around material-ui's TextField component when using styled-components and inline styling. Any solutions to this issue? Interestingly, the inline width property is functioning correctly, unlike the styled-component w ...

How to center an image vertically inside a link using CSS

My goal is to vertically align an image inside an anchor element using the following code: <ul class="thumbnails"> <li class="span2"> <a href="#" class="thumbnail"> <img src="http://www.forodefotos.com/attachme ...

Issue with scrollable multilevel dropdown menu

Dealing with an extensive menu list, I aimed to restrict them using a scroll. In the demo on CodePen, everything works fine without the scroll. However, upon adding overflow-y:scroll; height:200px;, it leads to an overflow-x issue and hides all the dropd ...

Using jQuery to create a div that animates when scrolling

Recently, I came across this interesting code snippet: $(document).ready(function(){ $(window).scroll(function(){ if($("#1").offset().top < $(window).scrollTop()); $("#1").animate({"color":"#efbe5c","font-size":"52pt", "top":"0", "position":"fix ...

Transforming a flat TypeScript array into a nested object structure

I'm working on implementing a user interface to offer a comprehensive overview of our LDAP branches. To achieve this, I plan to utilize Angular Materials Tree as it provides a smooth and intuitive browsing experience through all the branches (https:// ...

Displaying JSON data in a popup window resembling a download prompt

I'm a beginner in front end development and facing difficulty in displaying JSON in a new window. Currently, I'm allowing users to download the JSON file like this var blob = new Blob([$scope.data], {type: 'json'}); ...

Locate the table cell that contains certain text, then identify its surrounding elements such as parent elements and

Currently, I am working on a task that involves finding a specific <td> element in a table using Python Selenium. I have successfully located the element based on certain text content it contains. However, upon calling the parent method on the select ...

failure to render updated content after modification of variable

I am facing an issue with triggering a function in the component: componentA.ts html = 'hey'; this.onElementSelected(r => this.change()); public change() { console.log(this.html); if (this.html === 'hey&ap ...

Seeking assistance with implementing Styles using the .css() function in Jquery. Any guidance is appreciated

This particular style is exactly what I am looking for. body{ background: url("img/Background_Home.jpg") no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; ...

The Angular Interceptor encounters difficulties in accurately determining the timing of API responses when multiple requests are made simultaneously

Steps to replicate the issue: The initial API call responds in 600ms. While the first API call is being processed, another 4 API requests are sent to the interceptor, which adds an additional second to the process. The problem arises when the interceptor ...

Having difficulty pushing code from the Vs Code interface to gitlab. Receiving error message "Git: [email protected]: Permission denied (publickey, keyboard-interactive)"

Being a Mac user, I've encountered an issue where my VS Code connection to GitLab seems incomplete. While I am able to commit code using the VS Code interface, I struggle with pushing the code to the repository directly from VS Code. Instead, I resort ...

Leveraging an HTML form for searching and fetching data from MySQL Workbench using PHP

I'm currently working on fetching data from my database by utilizing an HTML form and establishing a PHP connection to my SQL workbench. The data retrieval is successful, as it appears at the top of my webpage. However, I am facing issues with executi ...

The bottom section of the main page

I've successfully implemented a footer that sticks to the bottom of each page as intended. However, I'm facing an issue when there's a large amount of text on a particular page that requires scrolling. The scroll continues beyond the footer, ...

Attempting to create a footer design featuring buttons aligned to the left and right sides

I am trying to create a layout similar to the bottom of Google's homepage using this code. However, no matter what I try, the "lists" are still appearing vertically instead of horizontally. My goal is to have three columns of links positioned side by ...

Arrange a group of users in the middle

Looking for some help with this specific code snippet .selection_user { display: block; background-color: #2D2C31; text-align: center; line-height: 75px; } <div class="select_user_menu"> <div class="selection_user">User1</div> ...

Issues with tsconfig Path Aliases in Angular 8+ when used in .spec files

While working on Angular testing, I encountered an issue where my spec files were not recognizing paths and displaying a red squiggle import warning in VS Code (and appearing under Problems), even though they functioned properly otherwise (testing worked, ...