Anusha Honey
Anusha Honey

Reputation: 917

How do I align items in a td?

This is a part of my table. I have a button and 2 images in the td. I want to move them to the center. How do I do it? I have tried padding, margin. But they doesn't work.

<td align="center" style="width: 200px;">

  <input type="button" name="submit" onClick="mySubmit();"
         style="position: relative; float: left; top: 10%" value=" GO ">

  <a href="#" style="position: relative; float: left; top: 2%;" onClick="mySubmit();">
    <img src="../images/refresh.png" style="position:relative;">
  </a> 

  <input type="checkbox"  name="upsCheckbox" id="upsCheckbox" onChange="setRefresh(this.checked)"/>

  <a href="#" style="position: relative; float: left; top: 2%;" onClick="enterFullscreen();">
    <img src="../images/FullScreen.jpg" style="position: relative; top:2%;">
  </a>

</td>

Upvotes: 11

Views: 39484

Answers (4)

RbG
RbG

Reputation: 3193

i think you want horizontally center ... text-align:center will do the trick

CSS::

td input[name="submit"], td input[name="upsCheckbox"]{

   text-align:center;

}

Upvotes: 2

biziclop
biziclop

Reputation: 14596

Example: http://jsfiddle.net/VEJk7/

Simplified HTML:

<table>
  <tr>
    <td style="width: 400px;">
      <input type="button" value=" GO ">
      <a href="#"><img src="1.jpg"></a> 
      <input type="checkbox">
      <a href="#"><img src="2.jpg"></a>
    </td>
  </tr>
</table>

CSS:

td {
    vertical-align: middle;
    text-align: center;
}

td a, td input, td img {
    vertical-align: middle;
    display: inline-block;
}

Upvotes: 11

Sasidharan
Sasidharan

Reputation: 3740

You can see a new div has been added inside TD with margin auto and width..

HTML

<td align="center" style="width: 200px">
    <div style="margin:auto;width:120px;">
              <input type="button" name="submit" onClick="mySubmit();" style="position:relative;float:left;top:10%"value=" GO ">
              <a href="#" style="position:relative;float:left;top:2%;" onClick="mySubmit();">
                    <img src="../images/refresh.png" style="position:relative;">
              </a> 
              <input type="checkbox"  name="upsCheckbox" id="upsCheckbox" onChange="setRefresh(this.checked)"/>
              <a href="#" style="position: relative;float:left;top:2%;" onClick=" enterFullscreen();">
                  <img src="../images/FullScreen.jpg" style="position: relative;top:2%;">
              </a>
   </div>
</td>

Outcome

enter image description here

Upvotes: 0

Farid Imranov
Farid Imranov

Reputation: 2075

May be I hadn't understand your question exactly, but I edited your code like following:

<table>
<td align="center" style="background-color: green; width: 200px;" >
    <input type="button" name="submit" onClick="mySubmit();" value="GO " />
    <a href="#" onClick="mySubmit();">
         <img src="../images/refresh.png" />
    </a> 
    <a href="#" onClick="enterFullscreen();" >
        <img src="../images/FullScreen.jpg" />
    </a>
    <input type="checkbox"  name="upsCheckbox" id="upsCheckbox" onChange="setRefresh(this.checked)"/>
 </td>
</table>

here is fiddle : (http://jsfiddle.net/bf26T/)

Upvotes: 0

Related Questions