The alignment of an image within a bootstrap table cell may not appear centered

I am struggling to center an image in a table cell that is wider than the image itself. I have tried using the text-center and align-middle classes in Bootstrap, but the image remains on the left side of the cell. Since I am new to Bootstrap, I am not familiar with any other techniques to achieve this.

<div class="table-responsive">
    <form name="frmPayment" method="post" id="frmPayment" action="viewcart.php">
     <?php
                                $str = "<table class='table table-striped table-hover'>";
                                $str .= "<thead><tr><th class='text-center col-md-1'>Sr#</th><th class='col-md-5'>Product Name</th><th class='text-center col-md-1'>Quantity</th><th class='col-md-1 text-center'>Price</th><th class='col-md-1 text-center'>Sale Price</th><th class='col-md-1 text-center'>Sub Total</th><th class='col-md-1 text-center'>Photo</th><th class='text-center col-md-1'>Action</th></tr></thead>";
                                $products = $_SESSION["orders"];
                                // pr($products);
                                //pr($products_info);
                                $p = count($products);
                                $str .= "<tbody>";
                                $total = 0;
                                $i = 0;
                                /*pr($products);
                                exit;*/
                                foreach($products as $key=>$val)
                                {
                                    //echo $key;
                                    $i = $i+1;
                                    $qty = $products[$key]["qtydtl"];
                                    $price = $products_info[$products[$key]["dt_prooduct_id"]]->price;
                                    $sale_price = $products_info[$products[$key]["dt_prooduct_id"]]->sale_price;
                                    $sale = $products_info[$products[$key]["dt_prooduct_id"]]->sale;
                                    $sub_total = (($sale==1 && $sale_price?$sale_price*$qty:$price*$qty));
                                    $total = $total+$sub_total;
                                    $str .= "<tr><td align='center' class='col-md-1'>".($i)."</td><td class='col-md-5'>".$products_info[$products[$key]["dt_prooduct_id"]]->name."</td><td class='text-center col-md-1'><input class='bxqty' type='text' name='quantity[]' value='".$qty."' size='5' /><input type='hidden' name='arr_keys[]' value='".$products[$key]["dt_prooduct_id"]."' size='5' /></td><td class='col-md-1 text-center'>".number_format($price)."</td><td class='col-md-1 text-center'>".number_format($sale_price)."</td><td class='col-md-1 text-center'>".number_format($sub_total)."</td><td class='col-md-1 align-middle'><img class='img-rounded img-responsive text-center' width='50' src='".$site_path."upload_prdimgs/".$products_info[$products[$key]["dt_prooduct_id"]]->image_name."' /></td><td class='text-center col-md-1'><a class='btnRemove btn btn-primary' href='#' data='".$key."'>Remove</a> </td></tr>";
                                }
                                $str .= "<tr><td class='col-md-1'>&nbsp;</td><td class='col-md-5'>&nbsp;</td><td class='text-center col-md-1'>&nbsp;</td><td class='col-md-1 text-center'></td><td class='col-md-1'></td><td class='col-md-1'></td><td class='col-md-1'></td><td class='text-center col-md-1'><b>Total:</b>&nbsp;".number_format($total)."</td></tr>";
                                //$str .= "<tr><td class='col-md-12 text-right'><b>Total:</b></td></tr>";
                                $str .= "<input type='hidden' name='action' id='action' value='' />";
                                $str .= "<tr><td class='col-md-1'>&nbsp;</td><td class='col-md-5'>&nbsp;</td><td class='text-center col-md-1'>&nbsp;</td><td class='col-md-1 text-center'></td><td class='col-md-1'></td><td class='col-md-1'></td><td class='text-center col-md-1'><input type='button' name='btnUpdate' id='btnUpdate' class='btn btn-success' value='Update Order' onclick='updateOrder();' /></td><td class='text-center col-md-1'><input type='button' name='btnOrder' id='btnOrder' class='btn btn-primary' value='Confirm Order' onClick='confirmOrder();' /></td></tr>";
                                $str .= "</tbody></table>";
                                echo $str;
                                ?>
                            </form>
                        </div>

Answer №2

Here's a simple solution for your problem. You applied the image responsive class to the image, which already sets display:block. To center the image, you can use margin: 0 auto:

.product .img-responsive {
    margin: 0 auto;

Hope this resolves your issue!

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

Remove any errors as soon as the input field becomes valid

My current setup involves AngularJS with node.js. To handle errors, I have devised the following strategy: node router effect.js: router.post('/', function(req, res, next){ req.checkBody('name', 'Eff ...

Dynamic Data Display

I'm experiencing an issue where the data is not displaying in the table div when using an Ajax call to load the table. The page appears blank upon return, and I have tried using $('#groupTable').load(data); without any success. If anyone can ...

The homepage is displayed below the navigation bar

import Home from './components/Home/Home.jsx' import Navbar from './components/Navbar/Navbar' import {BrowserRouter, Routes, Route} from "react-router-dom" export default function App() { return ( <BrowserRouter> ...

Animate the transition of the previous element moving downward while simultaneously introducing a new element at the top

I currently have a hidden element called "new element" that is controlled by v-if. My goal is to create a button labeled "display" that, upon clicking, will reveal the new element on top after sliding down an old element. How can I achieve this using CSS ...

What is the best way to effectively nest Bootstrap grid without needing to enclose columns within another

I need to create a grid layout with 8 columns on the left and 4 columns on the right. Within the 4 columns on the right, I want to divide it into 4 smaller columns and 8 larger columns. It is crucial that the grid layout does not wrap onto multiple lines. ...

The method for transforming all headers into permalinks with jquery/javascript

I am looking for a way to transform all headers on a page into clickable permalinks using jQuery or JavaScript. Here is the HTML code: $('h3').each(function() { var id = $(this).attr('id'); if (id) { //Check if the element has a ...

Unable to adjust the top padding of the navbar to 0 pixels

Having recently started learning HTML and CSS, I am encountering an issue with the padding on my navbar. I am unable to get it to align with the top of the site as there is a persistent space between the navbar and the top. Below is my HTML code: <!do ...

Customize the drawer background in Vue Material

Recently, I developed a vuejs application incorporating Google's material design components. I've been exploring options to customize the background color. <template> <div class="page-container"> <md-app> ...

Only show a single li element in CSS at a time

I'm working with Angular 2 and I have a list: <ul> <li *ngFor="let show of (ann)"> {{show}} </li> </ul> I want to show one item from the list every 3 seconds in an infinite loop. Here&apos ...

Using JavaScript's document.write method to display HTML code, along with a variable retrieved from a Flash application

Can I ask two questions at once? Firstly, how can I achieve the following? document.write(' <div id="jwplayer"> <center> <div id='mediaplayer'></div> <script type="text/javascript"> jwplayer('mediapl ...

scrape particular data from a table using scrapy

Currently, I am utilizing scrapy to extract content from a website specifically located within a particular <td> tag. The guide provided demonstrates downloading all the information, however, I only require the data from one individual <td>. As ...

Incorporate Javascript to smoothly transition a div into view, display it for a specified duration, gradually fade it out, and ultimately delete

I am excited to experiment with toast notifications by creating them dynamically. Each toast has a unique id number and I increment a counter every time a new one is created. The current functionality includes the toast sliding down, staying visible for 3 ...

Executing an SQL delete query with a button click using a JavaScript function in PHP

I have created a setup with three essential files - index.html, database.php, and function.js. In database.php, there is a form generated containing a delete button that triggers the deletion SQL query when clicked. The primary objective is to present a ta ...

A one-page digital space that functions as a dynamic slide show

Check out this cool website I want to emulate. The site is a single-page design where you can navigate vertically using various methods like keyboard, mouse, scroll, or swipe gestures. There are carousels that allow left and right navigation. Each section ...

Unable to make the Show/Hide Loading GIF function work as intended

Could someone please help me with my code? I'm trying to display a loading GIF image while waiting for an ajax request to complete. When the button is pressed, I want the loader to be shown until the data is returned from the server. I would greatly ...

Expanding and collapsing DIV elements using JavaScript upon clicking navigation menu items

At present, the current code unfolds the DIVs whenever a user clicks on a menu item. This results in the DIV folding and unfolding the same number of times if clicked repeatedly on the same link, without staying closed. My desired functionality is to have ...

Utilizing pure CSS to target the first and last classes

I want to use pure CSS to select only the first and last classes throughout the entire document. In my scenario, the structure looks like this: <div class="Container"> <div> <div class="Parent"></div> <pre> ...

Strange spacing appears after image tags

My efforts to remove the space (red) between the <img> and the <div> have been unsuccessful. I have minimized it as much as possible. After researching similar threads, it seems that whitespace or newlines between inline-box elements can cause ...

Show submenu upon hovering and make sure it remains visible

Is there a way to keep a submenu displayed and the background color changed even after moving the mouse away from the menu item onto the submenu? This is my HTML: <div class="shoplink"><a>Online Shop</a></div> <div id="shop-men ...

Creating visual representations from information gathered in SQL Server, utilizing nodejs to generate the graph, and presenting the results in HTML

I have successfully established a connection to my database in server.js, and I am able to retrieve data and view it in the terminal. However, presenting this information in HTML, or even creating a graph to display it, has been a challenge. Any helpful ...