Issue encountered: difficulty with vertical alignment in table cell containing both text input and image

I am facing an issue with aligning two items (an input text and an image) within a cell of a table. Despite trying various methods like using vertical-align:middle, margin top, padding, and setting height to 100%, I haven't been able to achieve the desired vertical alignment.

The code snippet is as follows:

<table cellspacing="0" rules="all" border="1" id="Origen" style="width:100%;border-collapse:collapse;">
            <tr>
                <td class="cabeceraDG"> Origen</td><td class="cabeceraDG"> Centro</td><td class="cabeceraDG"> Usuario</td>
            </tr><tr style="white-space:nowrap;">
                <td class="campoOpcional">oficina</td><td class="campoOpcional" align="center" style="width:150px;">
                                <input name="Origen$ctl02$referenciaTextBox" type="text" value="0000" id="Origen_ctl02_referenciaTextBox" class="campoOpcional" onblur="return validate(this)" ref="0991" />
 <input type="image" name="Origen$ctl02$imgBtnGuardarCentro" id="Origen_ctl02_imgBtnGuardarCentro" title="Guardar" AutoPostBack="false" src="https://s30.postimg.org/usmf6nsn5/boton_Abonar.gif" onclick="return ASPxClientEdit.ValidateGroup();  msGuardar();" style="border-width:0px;" />
                             </td><td class="campoOpcional">TEST</td>
            </tr>
        </table>

Here is a link to an example demonstrating the problem: https://jsfiddle.net/javierif/nmpmj1eh/

Answer №1

To make it work, simply add vertical-align: middle to the .campoOpcional input class. To visualize the changes, refer to the demo below:

.campoOpcional input {
  vertical-align: middle;
}
<table cellspacing="0" rules="all" border="1" id="Origen" style="width:100%;border-collapse:collapse;">
  <tr>
    <td class="cabeceraDG">Origen</td>
    <td class="cabeceraDG">Centro</td>
    <td class="cabeceraDG">Usuario</td>
  </tr>
  <tr style="white-space:nowrap;">
    <td class="campoOpcional">oficina</td>
    <td class="campoOpcional" align="center" style="width:150px;">
      <input name="Origen$ctl02$referenciaTextBox" type="text" value="0000" id="Origen_ctl02_referenciaTextBox" class="campoOpcional" onblur="return validate(this)" ref="0991" />
      <input type="image" name="Origen$ctl02$imgBtnGuardarCentro" id="Origen_ctl02_imgBtnGuardarCentro" title="Guardar" AutoPostBack="false" src="https://s30.postimg.org/usmf6nsn5/boton_Abonar.gif" onclick="return ASPxClientEdit.ValidateGroup();  msGuardar();"
      style="border-width:0px;" />
    </td>
    <td class="campoOpcional">TEST</td>
  </tr>
</table>

Answer №2

Here is the code you need to use:

input should be placed inside the optionalField where the vertical-align property is required.

.optionalField input {
  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

What could be causing the issue of nth-child blocking the functionality of a:hover styles?

I have a unique collection of images that are styled to resemble polaroid pictures. Each image is given a slight rotation. a.polaroid { transform: rotate(-2deg); } On hover, a scale transformation is applied. a.polaroid:hover { transform: scale(1 ...

I'm working with Angular 12, Bootstrap 5, and ngPrime, and I'm looking to overlap a p-dialog with another element in my project

Is there a way in Angular 12 with Bootstrap 5 using ngPrime to overlap a p-dialog over any other element without using z-index and CSS, solely relying on PrimeNG? I have tried using z-index with: .my-class{ z-index: 2147483647 !important; } However, ...

Creating and sending HTML formatted emails using Django 1.7

The function send_mail() now accepts a new parameter - html_message. Check out the official documentation for more details. I have an email.html file and I need to send an html version of my message using Django 1.7. Can someone provide me with an example ...

css the vertical column is unable to reach 100% vertical

Check out my website at I need help getting the black column with my thumbnails to extend all the way down on the site. Here is the CSS code for the thumbnails: #thumbnails { position:absolute; top: 110px; width: 190px; height: 100%; ...

Disregarding the Syntax of jQuery Mobile

Is there a way to override jQuerymobile's formatting and classes when styling an element? I want to apply my own custom style. I attempted using $.mobile.ignoreContentEnabled = true; in the pageInit function, followed by adding data-role="none" to th ...

Is there a way to adjust the placement of text in an HTML document?

Just starting out with web development and created some HTML code: <html> <body> {errors} <p>Input your numbers:</p> <form method="post" action="."> <p><inpu ...

Discover the method for measuring the size of a dynamically generated list

I'm currently working on a chat box that displays messages as a list. One issue I'm facing is that when I click on the start chat button, the chat box opens but the length of the list always remains zero. How can I resolve this problem? $(docu ...

Activate the dropdown menu when ul element is in focus

I am working on creating a dropdown navigation using pure CSS. I want the dropdown menu to appear when clicking on the ul. The issue I am facing is that simple ul:focus > ul does not seem to work, even though there is an anchor within it. However, the : ...

The styled horizontal list item has a background color that is not covering the entire

After setting up my CSS, I noticed a discrepancy in how the background color behaves when hovering over links in the navigation versus links in the footer. While the entire "button" area is filled with the background color in the nav, only the space behind ...

Easily validate the contenteditable attribute of <td> element

I am currently working on a table that displays data from a MYSQL database. Whenever a user makes changes to an element in the table, I want the database to be updated using AJAX. Below is my JavaScript code for sending data in an editable row. function s ...

As I scroll past the top or bottom of the page, the body's background color transitions to a new shade

I am encountering an issue with my next.js app where the body background color is set to black. Here is the code in globals.css: body { background-color: black; padding: 0; margin: 0; font-family: 'Titillium Web', sans-serif; } However, ...

Switching the checkbox value upon clicking a div element

One challenge I am facing is with a checkbox that saves its value and title in the local storage when clicked. This checkbox is located within a div, and I want the checkbox value to change whenever any part of the div is clicked. Despite my efforts, I hav ...

The tab functionality in Bootstrap is malfunctioning

Struggling with implementing tab functionality on my navigation bar using Bootstrap. The tab links change the URL, but the content of the tabs doesn't update accordingly. I'm using Bootstrap 4 - do I need to add jQuery code to make this work? Wha ...

Sorry, but we are experiencing difficulties processing your request at the moment. HTTP ERROR 500: We are unable to locate the

My code seems to be functioning correctly when connecting to the database, but I'm encountering an error. Here is the code snippet: <?php include 'header.php'; ?> <!DOCTYPE html> <html> <head> <t ...

There was a SyntaxError that caught me by surprise in my Javascript code when it unexpectedly encountered

I have been encountering an error in my code consistently, and I am struggling to comprehend why this is happening. The problematic area seems to be in line 29 of my Javascript file. HTML <link href="Styles12.css"; type="text/css" rel="stylesheet"> ...

Meta tags are causing issues with HTML5 validation on the website

Striving to enhance the HTML validity of my website, I encountered several errors in the meta tags that are marked as invalid. Unfortunately, I am unsure how to modify them to rectify these errors. <meta http-equiv="X-UA-Compatible" content="IE=edge,ch ...

Trigger event upon variable modification

Currently, I am working on a school project that involves creating a website where users can listen to music together. I have implemented a button that allows the user to listen to the same song another user is currently playing at the right position. Howe ...

Enhancing the appearance of a Textfield with PHP and HTML styling

How can I adjust the width and center text in a textfield within a container? <input type=text style=width:90%text-align:center value=" . $rows[mysql_field_name($sql_result, 3)] . "> Setting the width in the style attribute works when isolated like ...

Creating a CSS binding for width: a step-by-step guide

I have a complex layout with multiple elements in different divs that need to be aligned. Hardcoding the width or using JS on page load to specify values in pixels both seem like messy solutions. How can I achieve this without causing a zigzag effect? Her ...

Tips for efficiently removing a user as an administrator

Whenever a user logs in or registers, I save their session and cookie information and also add certain details to the database. Login/Register Module (login/register.php) $_SESSION['userid'] = $userid; $selector = base64_encode(random_bytes(9)) ...