简体   繁体   English

如何在同一行上对齐文本和输入框?

[英]How can I align my text and input box on the same row?

I tried using bootstrap for aligning my text and input box on the same row but it's not working: 我尝试使用引导程序在同一行上对齐我的文本和输入框,但是它不起作用:

<tr id="price_box">
    <div class="row">
        <th>Price:</th>
        <td>
            Rs&nbsp;
            <input id="price" name="price" type="text" value="">
            <span class="pricebox_end">.00</span>
    </div>
    <br>(Optional - do not include period, comma or cents)
    <div id="err_price" style="display: none">
        <span class="warning nohistory"></span>
    </div>
    </td>
</tr>

在此处输入图片说明

The above is just a fragment, but I could make a fiddle if it helps. 上面只是片段,但如果有帮助,我可以摆弄。 Maybe you know what I should do to make the texts and the input box display on the same row? 也许您知道我应该怎么做才能使文本和输入框显示在同一行上?

Update 更新

The following rendered them on the same row. 以下内容将它们呈现在同一行上。

 <tr id="price_box">

            <th>Price:</th>
            <td>

<div style="float:left">
                Rs
</div>
                &nbsp;<input id="price" name="price" type="text" value=""><span class="pricebox_end">.00</span>




                    <br>(Optional - do not include period, comma or cents)

With the CSS. 与CSS。

#price {
    float:left;
}
.pricebox_end {
    float:left;
}

I had to keep the table because of complex side effects if I removed the table. 如果删除表,由于复杂的副作用,我必须保留表。

You have malformed HTML with tables and Bootstrap thrown in. I would just use the grid system: 您将HTML格式与表和Bootstrap一起插入。我只使用网格系统:

<div class="row">
    <div class="col-md-3">
         Price:
    </div>
    <div class="col-md-3">
        <input id="price" name="price" type="text" value="" />
    </div>
    <div class="col-md-3">
        Rs
    </div>
    <div class="col-md-3">
        <span class="pricebox_end">.00</span>
    </div>
</div>

The grid system is a nice replacement for HTML tables. 网格系统可以很好地替代HTML表。 Bootstrap lets you write less HTML and gives you responsiveness out of the box. Bootstrap使您可以编写更少的HTML,并提供了开箱即用的响应能力。

The div <div class="row"> HTML element in your code is not a valid direct child element for <tr> and adds unexpected behaviour. 代码中的div <div class="row"> HTML元素不是<tr>的有效直接子元素,并且会添加意外的行为。

Further, the <input id="price" .. > element wasn't closed, causing the issue of the elements not being rendered on the same row. 此外,未关闭<input id="price" .. >元素,从而导致元素未在同一行上呈现的问题。 You do not need to float your elements. 您无需浮动元素。

You can close an input element by doing <input id=price .. /> or <input id=price ../></input> 您可以通过执行<input id=price .. /><input id=price ../></input>来关闭input元素

I've cleaned up your code below. 我在下面清理了您的代码。

<tr id="price_box">
    <th>Price:</th>
    <td>
Rs <input id="price" name="price" type="text" value="" /><span class="pricebox_end">.00</span>
        <br />
        (Optional - do not include period, comma or cents)
    </td>
</tr>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM