Error css: vertical align in td with input text and image

半世苍凉 提交于 2019-12-12 19:36:54

问题


I have a table with a cell with 2 items (input text and image). I try to align them vertically but it does not work.

I try use vertical-align:middle, margin top, padding, try set height:100%, etc...

The code is simply:

<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>

And here an example with the problem: https://jsfiddle.net/javierif/nmpmj1eh/


回答1:


Add vertical-align: middle to .campoOpcional input and it works - see 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>



回答2:


Use this code,

input inside the campoOpcional needed vertical-align

.campoOpcional input {
  vertical-align: middle;
}


来源:https://stackoverflow.com/questions/41384702/error-css-vertical-align-in-td-with-input-text-and-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!