inputError
inputError

Reputation: 610

Center align tds inside a table without creating empty tds?

I have a table and i want 2 tds centered like ** Hello | World ** without adding empty tds before and after ? I have something like this which works fine but i dont want to add extra tds and do it the same way

<table class="alignCenter" style="border:1px solid black">  
                <tr>
                <td>&nbsp;
                </td>
                    <td class="searchField">
                        <select id ="exactField">
                             <option value="default">Request num</option>
                        </select>   
                        <input type="text" class="textBox" id="exactValue"/>
                    </td>   
                    <td class="tableButtons">
                        <button type="button" class="clear" ><bdi>${Clear_Button}</bdi></button>
                        <button type="button" class="submit" ><bdi>${Search_Button}</bdi></button>
                    </td>
                    <td>&nbsp;
                    </td>
                </tr>
            </table>

CSS

table,.alignCenter {
width: 1000px;
margin: 0px auto;
text-align: left;
table-layout: fixed;
font-size: 0.9em;
}


table tr td,.alignCenter tr td {
overflow: hidden;
border: 1px solid black;
vertical-align: top;
padding: 5px 2px 5px 2px;
}

.alignCenter tr td {
text-align : center;
}
.tableButtons {
 width:250px;   
}

.searchField {
 width:300px;
 }

Fiddle

Upvotes: 0

Views: 1377

Answers (2)

Lee Hibberd
Lee Hibberd

Reputation: 99

would something like this work?

html..

<table style="border:1px solid black">  
                    <tr>
                        <td class="alignright" >
                            <select id ="exactField">
                                 <option value="default">Request num</option>
                            </select>   
                            <input type="text" class="textBox" id="exactValue"/></td>
                        <td class="alignleft" >
                            <button type="button" class="clear" ><bdi>${Clear_Button}</bdi></button>
                            <button type="button" class="submit" ><bdi>${Search_Button}</bdi></button>
                        </td>
                    </tr>
                </table>

css..

table,.alignright {
  width: auto;
  margin: 0px auto;
  text-align: right;
  table-layout: fixed;
  font-size: 0.9em;
}
table,.alignleft {
  width: auto;
  margin: 0px auto;
  text-align: left;
  table-layout: fixed;
  font-size: 0.9em;
}


.tableButtons {
  width:250px;  
}

.searchField {
  width:300px;
}

FIDDLE

Upvotes: 0

Mr. Alien
Mr. Alien

Reputation: 157284

Why you even need 4 td's to accomplish something like that?

Just use a single td (I would use a simple div for this)

Demo

<table class="alignCenter" style="border:1px solid black">  
    <tr>
        <td>
            <select id ="exactField">
                 <option value="default">Request num</option>
            </select>   
            <input type="text" class="textBox" id="exactValue"/>            
            <button type="button" class="clear" ><bdi>${Clear_Button}</bdi></button>
            <button type="button" class="submit" ><bdi>${Search_Button}</bdi></button>
        </td>
    </tr>
</table>

Upvotes: 3

Related Questions