Question

I want to have a form which consists of different input fields. On some rows there should be two input fields. The second one should be aligned right.

jsFiddle

HTML:

<table>
    <tr>
        <td>
            <input type="text" name="first-name" class="form-first-name" />&nbsp;
            <input type="text" name="last-name" class="form-last-name" />
        </td>
    </tr>
    <tr>
        <td class="empty-row">&nbsp;</td>
    </tr>
    <tr>
        <td>
            <input type="text" name="address-1" class="form-address-1" />
        </td>
    </tr>
</table>

CSS:

.form-address-1 {
    width: 100%;
}

.form-first-name, .form-last-name {
    width: 46%;
}

.form-last-name {
    float: right;
}

My problem is that the input fields have different sizes and so the size of the row somehow changes. I tried to set the width of tr without success. How can I align the second input field right?

Was it helpful?

Solution 2

Its a box-layout issue.

check with the inspector, and you'll see that your address input is overflowing its row. (thats because 100% + default margin/padding = more than 100%)

Working Fiddle

Add this to your CSS

*
{
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
}

OTHER TIPS

You can do it like:

 <td>
      <span style="float:left">
          <input type="text" name="first-name" class="form-first-name" /></span>
       <span style="float:right">
           <input type="text" name="last-name" class="form-last-name" /></span>
 </td>

http://jsfiddle.net/KxUgt/8/

Set the width of the table, not the tr.

make use of min-width: and also make .form-first-name{float:left;}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top