Obtain the structure of the Bootstrap table

Currently in the process of learning, I am encountering an issue with a Bootstrap table. Specifically, I am trying to center the two columns (trucks and cars) as shown on this image:

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

The goal is to have the trucks and cars centered so that when more are added, they remain centered. Additionally, the empty row needs to be removed.

   
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<table class="table table-bordered">
   <thead>
      <tr>
         <th scope="col">Trucks / Cars</th>
         <th scope="col">Lorem 1</th>
         <th scope="col">Lorem 2</th>
         <th scope="col">Lorem 3</th>
         <th scope="col">Lorem 4</th>
         <th scope="col">Lorem 5</th>
         <th scope="col">Lorem 6</th>
         <th scope="col">Lorem 7</th>
         <th scope="col">Lorem 8</th>
         <th scope="col">Lorem 9</th>
         <th scope="col">Lorem 10</th>
         <th>Lorem 11</th>
      </tr>
   </thead>
   <tbody>
      <tr>
         <td>Trucks</td>
         <td></td>
         <td></td>
         <td></td>
         <td></td>
         <td></td>
         <td></td>
         <td></td>
         <td></td>
         <td></td>
         <td></td>
         <td></td>
      </tr>
      <tr id="592">
         <th scope="row"></th>
         <td>Title 1</td>
         <td>Title 2.</td>
         <td>1</td>
         <td>1</td>
         <td>MTitle 3</td>
         <td>title 5</td>
         <td>title</td>
         <td>some</td>
         <td>01.10.2020</td>
         <td>15.10.2020</td>
         <td>
         </td>
      </tr>
      <tr style="border-top: 2px solid #006171">
         <td>Cars</td>
         <td></td>
         <td></td>
         <td></td>
         <td></td>
         <td></td>
         <td></td>
         <td></td>
         <td></td>
         <td></td>
         <td></td>
         <td></td>
      </tr>
      <tr id="592">
         <th scope="row"></th>
         <td>Title 1</td>
         <td>Title 2.</td>
         <td>1</td>
         <td>1</td>
         <td>MTitle 3</td>
         <td>title 5</td>
         <td>title</td>
         <td>some</td>
         <td>01.10.2020</td>
         <td>15.10.2020</td>
         <td>
         </td>
      </tr>
   </tbody>
</table>

I am still relatively new at this, so any assistance would be greatly appreciated.

Answer №1

Include rowspan=2 in the th element Give this a shot:

.table tbody th {
  vertical-align: middle;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<table class="table table-bordered">
   <thead>
      <tr>
         <th scope="col">Trucks / Cars</th>
         <th scope="col">Lorem 1</th>
         <th scope="col">Lorem 2</th>
         <th scope="col">Lorem 3</th>
         <th scope="col">Lorem 4</th>
         <th scope="col">Lorem 5</th>
         <th scope="col">Lorem 6</th>
         <th scope="col">Lorem 7</th>
         <th scope="col">Lorem 8</th>
         <th scope="col">Lorem 9</th>
         <th scope="col">Lorem 10</th>
         <th>Lorem 11</th>
      </tr>
   </thead>
   <tbody>      
      <tr id="592">
         <th scope="row" rowspan="2" class="text-center">Trucks</th>
         <td>Title 1</td>
         <td>Title 2.</td>
         <td>1</td>
         <td>1</td>
         <td>MTitle 3</td>
         <td>title 5</td>
         <td>title</td>
         <td>some</td>
         <td>01.10.2020</td>
         <td>15.10.2020</td>
         
         <td>
         </td>
      </tr>  
       <tr id="592">
         <td>Title 1</td>
         <td>Title 2.</td>
         <td>1</td>
         <td>1</td>
         <td>MTitle 3</td>
         <td>title 5</td>
         <td>title</td>
         <td>some</td>
         <td>01.10.2020</td>
         <td>15.10.2020</td>
         
         <td>
         </td>
      </tr>      
      <tr id="592" style="border-top: 2px solid #006171">
         <th scope="row" rowspan="2" class="text-center">Cars</th>
         <td>Title 1</td>
         <td>Title 2.</td>
         <td>1</td>
         <td>1</td>
         <td>MTitle 3</td>
         <td>title 5</td>
         <td>title</td>
         <td>some</td>
         <td>01.10.2020</td>
         <td>15.10.2020</td>
         <td>
         </td>
      </tr>
      <tr id="592">         
         <td>Title 1</td>
         <td>Title 2.</td>
         <td>1</td>
         <td>1</td>
         <td>MTitle 3</td>
         <td>title 5</td>
         <td>title</td>
         <td>some</td>
         <td>01.10.2020</td>
         <td>15.10.2020</td>
         <td>
         </td>
      </tr>
   </tbody>
</table>

Answer №2

Here:

<!doctype html>
<html lang="en">
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
    <table class="table table-bordered">
       <thead>
          <tr>
             <th scope="col"  style="text-align: center;">Trucks / Cars</th>
             <th scope="col">Lorem 1</th>
             <th scope="col">Lorem 2</th>
             <th scope="col">Lorem 3</th>
             <th scope="col">Lorem 4</th>
             <th scope="col">Lorem 5</th>
             <th scope="col">Lorem 6</th>
             <th scope="col">Lorem 7</th>
             <th scope="col">Lorem 8</th>
             <th scope="col">Lorem 9</th>
             <th scope="col">Lorem 10</th>
          </tr>
       </thead>
       <tbody>
          <tr>
             <td  style="text-align: center;">Trucks</td>
             <td></td>
             <td></td>
             <td></td>
             <td></td>
             <td></td>
             <td></td>
             <td></td>
             <td></td>
             <td></td>
             <td></td>
          </tr>
          <tr id="592">
             <th scope="row"></th>
             <td>Title 1</td>
             <td>Title 2.</td>
             <td>1</td>
             <td>1</td>
             <td>MTitle 3</td>
             <td>title 5</td>
             <td>title</td>
             <td>some</td>
             <td>01.10.2020</td>
             <td>15.10.2020</td>
          </tr>
          <tr style="border-top: 2px solid #006171">
             <td style="text-align: center;">Cars</td>
             <td></td>
             <td></td>
             <td></td>
             <td></td>
             <td></td>
             <td></td>
             <td></td>
             <td></td>
             <td></td>
             <td></td>
          </tr>
       </tbody>
    </table>
  </body>
</html>

Centers the text and removes the final row.

Answer №3

To center align data in a td element, you can use either the class "center" or "text-center":

<td class="center">Trucks</td>

Alternatively,

<td class="text-center">Trucks</td>

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

Is it possible to create a top bar that remains fixed at the top of the screen while the content below

Currently, I am dealing with a situation where I want the content to occupy 100% of the page, excluding the initial 100px from the top bar. However, my code seems to be malfunctioning. <style> #content{ display: block; height: 100%-100px; ...

When testing Angular, an error occurred stating that "mat-chip-list" is an unknown element for Jasmine and Karma

Whenever I attempt to run tests using Jasmine and Karma, an error message keeps popping up: 'mat-chip-list' is not recognized: 1. To ensure that 'mat-chip-list' is a valid Angular component, double-check that it is included in this mod ...

Error message "Module not found in Vue" occurs when changing image URL to an online image

I am currently working on a dynamic image display feature where I retrieve image names as strings from a backend. To manage a large number of images, I plan to store them online while maintaining the same logic for displaying them. Previously, I achieved t ...

Ways to access the properties of an HTML element with JQuery

Can anyone tell me how to extract the value from a specific HTML element using JQuery? For example: <span id="45463_test"></span> (the proper tags need to be used for the code to work correctly) Specifically, I am looking to retrieve the va ...

Sacred Grid Layout with Bootstrap 4

Trying to create a modified version of the Holy Grail layout using Bootstrap 4, but running into some issues. I want to have both my header and footer contained within the Fluid Center Column, while keeping all columns the same height. ------------------- ...

Finding a specific element on a web page can be accomplished by targeting its href attribute

I'm facing a simple task. I have a String with an href value, and my goal is to locate the web element on the webpage that includes that specific href. Here's what I'm trying: String href = "http://www.bing.com/images?FORM=Z9LH"; driver.fin ...

The html viewport size is altered by the mobile keyboard

One issue that arises when using percentage or viewport unit width and height for the <body> element is that the size of these elements will change when a mobile keyboard is invoked due to an input. I have extensively researched this problem without ...

How to send the file path to an API in JavaScript to convert it

I am currently working on a web application that allows users to upload a wav file and convert it to mp3 format. I have successfully implemented the wav to mp3 conversion and saving it to the project folder. However, I am facing an issue with dynamically p ...

I find it curious that I need to include the bootstrap link in the body of the HTML file rather than in the head, unlike the bootstrap

Check out the Bootstrap documentation here which states that we should add the link at the end of the body just before its closing tag. As a newcomer, I've noticed linking being done in the head section for non-bootstrap codes, leading me to feel a bi ...

What is the best way to give a user the option to select the destination for file uploads?

I currently have a basic upload form set up. Here's the HTML code: <html> <head> <title>Upload a File</title> </head> <body> <font face=verdana size=2> <form enctype="multipart/form-data" method="post" act ...

Error: String cannot be used for function prepare()

Before posting this, please wait to ensure it's not a duplicate. I've conducted thorough research and attempted all solutions, but still unable to resolve the issue. I consistently receive the error message "Fatal error: Call to a member function ...

Displaying output from multiple inheritance relationships on a terminal

I have the following code snippet that is causing unexpected output on my console. Currently, the output I am receiving is "this is aB", but what I actually need is to get constructor-related output on my console. For example, I want "this is aA" for the ...

How to position a full-width banner image in the center using CSS without causing scrollbars

I am facing a design challenge with my webpage where the content is 1000px wide. In the middle of this page, I want to showcase an image that is 600px high and 2000px wide. The tricky part is ensuring that this image remains 600px high, maintains its aspe ...

Tips for adding jQuery UI styling to elements generated dynamically

I have a challenge with generating text fields using jquery while applying jquery ui styling to the form. The issue is that the dynamically created elements do not inherit the css styles from jquery ui: let index = 0; $('#btn_generate').on(& ...

What is the best way to display an image in the navigation bar?

I've been struggling to display an image as the background for my navigation bar. Despite looking at various code samples and examples, I can't seem to fix my mistakes. Here is the HTML markup: <!--DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 ...

Click to collapse the Bootstrap navbar

Is there a way to collapse the Bootstrap nav bar when a user clicks on a nav-bar button instead of it staying open? <nav class="navbar navbar-default" role="navigation"> <div class="container-fluid"> <div class="navbar-header"> ...

Stopping the page from scrolling back to the top when an asynchronous update occurs in Angular

Once the asynchronous request is complete, I dynamically add a new element to the top with this code snippet: Array.prototype.unshift.apply(scope.conversation, conversation.data.message); The issue arises when the added element causes the scroll position ...

Tips on exporting the 'invisible section' as a PDF without it being displayed on the user interface

Kindly take a look at the concealed div element below. It is being utilized as a hidden component to structure the PDF contents for download as a PDF. The HTML elements are declared as follows. <div id="griddata" style="display:none;"> <div id= ...

Retrieve HTML elements from a string using PHP

Possible Matches: crawling a html page using php? Best methods to parse HTML I am trying to extract DOM elements from a string variable in my PHP script that contains an HTML page. How can I achieve this? For instance, if the string is something ...

Is an array necessary for updating only the last database record?

Requesting assistance from the PHP and SQL community as I am a novice in these areas. I have successfully created a database and implemented a form on an HTML page to update it. However, I am facing an issue where only the last record is being updated. I s ...