简体   繁体   English

如何防止两个元素包装?

[英]How to prevent two elements from wrapping?

I have the following for Google Chrome: 我的Google Chrome浏览器具有以下功能:

<table>
    <tr>
        <td width="80px">
            Text
        <td width="100%">
            <form>
                <input style="width:100%" type="text"/>
                <button>Submit</button>
            </form>
        </td>
        <td width="80px">
            Text
        </td>
    </tr>
</table>

The problem is when you resize the screen to something small, the Submit button wraps around under the textbox. 问题是,当您将屏幕调整为较小尺寸时,“提交”按钮会在文本框下方环绕。 How do I keep the "button" from wrapping (as in the button shows up below the textbox by a few pixels), while keeping the text box as wide as possible? 如何保持“按钮”不换行(如按钮在文本框下方显示几个像素),同时保持文本框尽可能宽?

http://jsfiddle.net/N36a7/ http://jsfiddle.net/N36a7/

<form>
    <table>
        <tr>
            <td width="80px">Text</td>
            <td width="100%">
                <input style="width:100%" type="text"/>
            </td>
            <td>
                <button>Submit</button>
            </td>
            <td width="80px">Text</td>
        </tr>
    </table>
</form>

Just give the button it's own td. 只要给按钮它自己的TD。

First, add the following styles to the form to prevent it from wrapping: 首先,向form添加以下样式以防止其包装:

form{
    white-space: nowrap;
}

Then remove the style width=100% from the input, which causes it to occupy all of the horizontal space within the td . 然后从输入中删除样式width=100% ,这将使其占据td内的所有水平空间。

JS Fiddle: http://jsfiddle.net/B4eWz/ JS小提琴: http //jsfiddle.net/B4eWz/

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

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