Tips on how to center an image within a table cell:1. Insert the image

I've been attempting to center an image within a bootstrap4 table cell, but it keeps appearing on the left and even overlaps the border. I've tried adding inline styles like text-align: center; vertical-align: middle; both to the table cell HTML markup and the CSS for the image, but without success. I also attempted wrapping the image in a span with no change. Additionally, my image for (.row.NotCompleted) isn't displaying at all, even though the file path is correct and it's in the same folder as the one that is displaying properly under (.row.Completed)

HTML

<div class="table-responsive container-fluid">
    <table class="table table-bordered table-hover">
        <thead>
            <tr class="">
                <th scope="col" colspan="4">Please review your biographical information and update any missing information:</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td style="width:50px; text-align:center; vertical-align:middle; white-space:nowrap;">
                   <span><img class="row @PreferredNameRowStatus" /></span>
                </td>
                <td>Preferred Name:</td>
                <td class="itemValue">@Model.PreferredName</td>
                <td>
                    <a id="PreferredNameLnk" href="#">Click Here to Update</a><br />
                </td>
            </tr>
            <tr>
</table>
</div>

CSS

.row.Completed {
        background-image: url("/images/Completed.png");
        background-repeat: no-repeat;
        background-size: 100% 100%;
        display: block;
    }

    .row.NotCompleted {
        content: url('/images/Notcomplete.png');
        background-repeat: no-repeat;
        background-size: 100% 100%;
        /* display set to block element */
        display: block;
        /*width: 100%;  */
        height: 100%;
    }

td img {
    max-width: 100%;
    height: auto;
}

Screenshot:

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

Answer №1

.row.Completed {
        background-image: url("/images/Completed.png");
        background-repeat: no-repeat;
        background-size: 100% 100%;
        display: block;
    }

    .row.NotCompleted {
        content: url('/images/Notcomplete.png');
        background-repeat: no-repeat;
        background-size: 100% 100%;
        display: block;
        height: 100%;
    }

td img {
    max-width: 100%;
    height: auto;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>


<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

<div class="table-responsive container-fluid">
    <table class="table table-bordered table-hover">
        <thead>
            <tr class="">
                <th scope="col" colspan="4">Please review your biographical information and update any missing information:</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td style="width:50px; text-align: -moz-center;
vertical-align: middle;
text-align: -webkit-center;">
                   <span><img src='https://www.talkwalker.com/images/2020/blog-headers/image-analysis.png' class="row @PreferredNameRowStatus" /></span>
                </td>
                <td>Preferred Name:</td>
                <td class="itemValue">@Model.PreferredName</td>
                <td>
                    <a id="PreferredNameLnk" href="#">Click Here to Update</a><br />
                </td>
            </tr>
            <tr>
</table>
</div>

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

Concentrate on user input in PHP programming

My goal is to create a PHP validation form where errors are displayed correctly every time. However, I am encountering an issue with setting focus on the input field with an error if one occurs. I have variables like $rut_error, $first_name_error, $last_na ...

How can I eliminate the gap above the footer in iframes alignment?

I have a setup with four iframes: header, menuframe, bodyframe, and footer. The menuframe and bodyframe are positioned next to each other with space between the footer and the menuframe/bodyframe. How can I remove this space? Here is the CSS: iframe{ ...

pure-react-carousel: every slide is in view

Issue I am encountering a problem where the non-active slides in my container are not being hidden properly. This results in all of the slides being visible when only one should be displayed. Additionally, some slides are rendering outside of the designate ...

Align watermark content to the far left side

Having trouble getting my watermark to align properly on the left side of my website's main content. Here is how it currently looks: The issue arises when I resize the screen or switch to mobile view, as the watermark ends up covering the main conten ...

VueJS is utilized to duplicate the innerHTML output value

Currently diving into the world of Vue, I encountered an issue while rendering an HTML text. My component template is a WYSIWYG editor. <template> <div id='editor_container'> <slot name="header" /> <div id='editor ...

Tips for adjusting the indentation of list items with CSS while working with floating blocks

Recently, I encountered a peculiar situation while working with floating images in a document. It seems that the list items indentation is being determined by the 'red line' rather than the expected 'green' one. I'm puzzled as to ...

Tips for notifying a user about leaving a page without saving their information

I created a small table where users can input product names and numbers. My question is, how can I notify the user if they try to leave the page without saving the entered information? <form action="index.php" method="post"> <input type="text" ...

Is there a way to turn off step navigation in bootstrap?

Displayed below is a visual representation of the bootstrap step navigation component. Presently, there is an unseen 'next' button located at the bottom of the page. When this 'next' button is pressed, it transitions from 'step-1 ...

Click anywhere on the body to conceal this element

I am currently working on a website where I have implemented a hidden menu that is functioning correctly. However, I want to make it so that when the menu is visible, users can click anywhere on the body to hide it. Unfortunately, my current code is not w ...

What is the best way to configure input fields as readonly, except for the one being actively filled by the user

Is there a way to make all input fields readonly except the one that the user is trying to fill data into? After the user loads the page index.php and attempts to input data into, for example, <input id="edValue2" ...>, I want to set all input field ...

One crucial factor to consider when dealing with dual screen setups is the

Imagine you have the following code snippet : <ul> <li>Menu1 <ul class="submenu"> <li class="firstmenu">submenu-1</li> <li>submenu-2</li> < ...

Using identical class names in different components was not possible as the CSS was not being contained within the styled component's scope

I am encountering a frustrating issue that seems to defy the essence of CSS in JS. The problem arises when I use styled-components and attempt to apply a classname that is already used higher up in the React component tree within a styled component. Surpri ...

Utilizing HTML5 history instead of hash URLs to preserve the user's browsing history

Our application is a single page that dynamically loads results based on query strings. The query string format we use is as follows: ?city=Delhi&pn=1 Within the SPA, there are different sections displayed on the same page. As users navigate through ...

Adaptable images - Adjusting image size for various screen dimensions

Currently, my website is built using the framework . I am looking for a solution to make images resize based on different screen sizes, such as iPhones. Can anyone suggest the simplest way to achieve this? I have done some research online but there are t ...

Issue with mobile.changePage() function not executing as expected

I created a basic code that generates a "Splash screen". For storing my data, I am utilizing localstorage. When I first load it, I retrieve data from a URL and I am able to navigate to different pages using $.mobile.changePage(). However, if the data is a ...

Finding a specific section on a webpage using AngularJS

Is it possible to create in-page navigation to a specific section within an Angular application without triggering the routing service? For example: The section we want to jump to: <a name="tips"> <div>Tips and tricks...</div> < ...

Issues with Disabling the Browser's Back Button with jquery

I have been attempting to prevent the back button from functioning in a specific Browser, Microsoft Bing. Interestingly, my code works only if I click somewhere in the window first. If I don't click anywhere and try to go back directly, it still allow ...

Tips for optimizing iframe loading times using the onload event

I am facing an issue with the timing of iframe loading while using a list of URLs as sources. I have created a child iframe and appended it to the DOM, then run the onload function for further processing. However, the time recorded for each iframe seems in ...

In the Bootstrap Grid system, all posts are aligned to the left side

I have created a gallery with Bootstrap in React.js. The posts are currently displayed using the bootstrap grid system, however, all posts appear on the left side and I am struggling to center them. Any ideas on how to achieve this? https://i.sstatic.net/ ...

What could be causing the modal not to close in Laravel Livewire?

I am currently using Laravel Livewire to handle record deletions in two database tables. However, I have encountered an issue with the modal not closing properly after deletion is successful. Interestingly, when I comment out a line of code that deletes d ...