Tips for vertically aligning table cells within Bootstrap

I am facing an issue with a bootstrap table that contains a form-inline in a specific column, which is causing the contents in other columns to not be vertically centered. (As shown in the 1st code snippet) How can I resolve this problem?

If I remove the form-inline from the table, all the content aligns properly. (As seen in the 2nd code snippet) Hence, it seems like the issue stems from having the form-inline within the table.

/* Adjust the width of the table cell based on content */

table th,
table td {
  width: 1%;
  white-space: nowrap;
}

.center-screen {
  align-content: center;
  justify-content: center;
  align-items: center;
  text-align: center;
  margin: 0 auto;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8>
  <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet"><
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a4c6cbcbd0d7d0d6c5d4e4908a928a95">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous"><
</head>

<body>
  <table class="table table-striped center-screen" style="max-width: 100%">
    <thead>
      <tr>
        <th>Symbol><
        <th style="width: 0.01%">Share><
        <th>Action><
      </tr>
    </thead>

    <tbody>
      <tr>
        <td>NVDA><
        <td style="width: 0.01%">1><
        <td>
          <form class="form-inline justify-content-center">
            <button type="submit" class="btn btn-danger" name="TSLA" value="Sell">
              <i class="fas fa-minus-circle"></i>
            </button>
            <input type="number" name="quantity" class="form-control" value="1" min="1" max="100" style="width:70px">
            <button type="submit" class="btn btn-primary" name="TSLA" value="Buy">
              <i class="fas fa-plus-circle"></i>
            </button>
          </form>
        </td>
      </tr>
  </table>
</body>

</html>

/* Adjust the width of the table cell based on content */
table th,
table td {
  width: 1%;
  white-space: nowrap;
}

.center-screen {
  align-content: center;
  justify-content: center;
  align-items: center;
  text-align: center;
  margin: 0 auto;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8>
  <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet"><
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1e7c71716a6d6a6c7f6e5e2a3028302f">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous"><
</head>

<body>
  <table class="table table-striped center-screen" style="max-width: 100%">
    <thead>
      <tr>
        <th>Symbol><
        <th style="width: 0.01%">Share><
      </tr>
    </thead>

    <tbody>
      <tr>
        <td>NVDA><
        <td style="width: 0.01%">1><
      </tr>
  </table>
</body>

</html>

Answer №1

Your table code has a default style that is causing it to be vertically aligned at the top.

Take a look at the following snippet:

.table td, .table th {
    padding: .75rem;
    vertical-align: top;
    border-top: 1px solid #dee2e6;
}

To fix this issue, you can override the default style by adding:
vertical-align: middle;

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

Implementing image change on dropdown selection using jQuery click event

I'm new to Jquery and JavaScript. I have a dropdown in my Keen template that displays 2 flags. I want to be able to click on the dropdown and select the corresponding flag. Most of the examples I found online use the select and options tags, but my co ...

I am having trouble with Popover and Tooltip not functioning properly in my browser

Today, I spent countless hours trying to implement popovers in my table to display additional information for each cell. However, I eventually discovered that the popovers do not seem to be functioning at all in my code. What could be causing this issue? D ...

Issue with rollover button function in Firefox and Internet Explorer when attempting to submit

I have created a rollover submit button using HTML and JavaScript: <input type="image" id="join" name="join" src="images/join.png" value="join"> My JS code implements the rollover/hover effect: <script type="text/javascript" charset="utf-8"> ...

Is there a way to implement a JavaScript function that can dynamically update the color scheme and background colors of all HTML pages within my website?

Looking for help on implementing a Javascript function that can modify the color schemes and background on all pages of my website. I tried using a function but it's only affecting one page. Can anyone offer guidance or suggestions? I'm finding t ...

How can I make rows appear dynamically when the user clicks a button?

I am trying to add rows dynamically when the user clicks on a button. I have created a script for this purpose, but unfortunately, it is not working as expected. Can someone please assist me with fixing it? <script> var i; i = 2; function AddR ...

Expanding Issue with Bootstrap Navigation

Hello! I am experiencing an issue with my navbar. The menu collapses, but it does not expand. I have used an example from Bootstrap and made some tweaks, but for some reason, it still doesn't expand properly. Below is the code that I have been workin ...

The concept of vertical alignment within the CSS Grid system

I am attempting to utilize CSS grids in order to vertically align an unordered list. However, I am encountering the following layout: *A******* *B * *C******* ********* * * ********* ********* * * ********* While the grid template rows a ...

Utilize PHPMailer to send pre-designed email templates

Apologies for the recurring queries. I'm still struggling to find a solution to this issue. Here's my Query: I have a form that allows users to choose between predefined and custom templates. The select option determines which template is displ ...

Prevent the body from being redirected to the static menu

One issue I'm facing is that when I resize my page, the body content ends up in the fixed menu area. I have been using a combination of pixels and percentages, but how can I prevent this from happening? Check out this example on jsfiddle <div cl ...

Submitting a form with multiple rows and submit buttons does not result in the submission of the submit array

In continuation of my previous question "Why does this multiple row table submit by row? Is this correct?", I have made some modifications to the original code: <tr> <td><input type='text' name='first[1]' value=' ...

To create a distinctive design, the HTML5 wrapper will specifically enclose the Header element

After using a border, I discovered that my wrapper is only wrapping the header and not extending down to the footer. Can anyone offer some guidance on how to wrap the entire content from the header to the footer? I've come across suggestions to speci ...

The code functions properly when tested on a local server, but doesn't produce any results when

Currently, I am working on customizing a premade website and have been tasked with making a modification. The goal is to implement a confirmation box that appears when a button to delete a meeting task is clicked, rather than immediately deleting it. Afte ...

Arranging items in the final row of a flexbox

, I am seeking a solution that goes beyond the repetitive ones provided before. I need to find a more efficient way to achieve my desired outcome based on the code snippet below. In examining the code, it's clear that the first row accommodates 6 ele ...

The presence of Bootstrap remains hidden unless space is designated for it

Question about Bootstrap 5.1.3: Is there a way to hide elements on a page using the bootstrap class ".invisible" without allocating space for them? Currently, when the elements are set to visible using the class ".visible", they occupy space on the page ...

How to effectively use graph paper with both major and minor grids in the background?

Looking to create a 100px by 100px image in Inkscape with major lines every 100px and minor lines every 10px. This will help verify viewport size when used as a repeating background. What's the best approach for this? Thinking of using #888888 for ma ...

Tips for effectively using the parseInt function to access and verify a span element from inside a chrome extension

Trying to utilize parseInt to ascertain if a span element is greater than or equal to 1 within my Google Chrome Extension. Attempting to monitor this "0" for changes and trigger a specific URL upon change - Refer to the Image View of the "inspect" option ...

"Looking to swap out the Angular theme's CSS stylesheet for your entire application? Here's

I was initially facing an issue while trying to import CSS through index.html as I kept getting a MIME type error: enter image description here The browser refused to apply the stylesheet from 'http://localhost:4200/css/pink-bluegrey.css' because ...

The best way to organize and position a Label and TextBox in C#

I need help styling the aspx file. The Label and TextBox elements are not aligned properly. I want the Label and TextBox to be positioned side by side with appropriate spacing. <div class="col-md-12"> <p> ...

Modify the class of a div element depending on the value of a data attribute

I am faced with a situation where I have an iframe and two different sets of CSS codes - one for landscape orientation and one for portrait orientation. However, these are not specifically for the device's orientation but rather for the content loaded ...

Showing the unique glyph ↶ on the screen

I am attempting to show a left curve arrow in my HTML code, and while it is successful in Firefox, Chrome, and Safari, I am encountering issues with Internet Explorer. As a newcomer to character encoding, I am unsure of the specific terms to search for t ...