Twitter引导程序 - 彼此相邻放置的前置输入元素重叠

时间:2013-02-17 07:10:16

标签: html css twitter-bootstrap textinput

我正在尝试将两个输入元素放在一起,在第一个输入上添加一个前置项目,使用display:table styles。然而,这导致第二输入元素与第一输入元素重叠。我尝试过使用box-sizing:border-box没有运气。似乎问题是我正在约束父div的宽度,然后将输入元素的宽度设置为100%,以便填充父级,但这根本不起作用。这是一个JSfiddle示例:

HTML

<div class="container">
    <div class="row">
        <div class="cell input-prepend">
            <span class="add-on">HI</span>
            <input type="text" />
        </div>
        <div class="cell">
            <input type="number"/>
        </div>
    </div>
</div>

CSS

@import url('http://twitter.github.com/bootstrap/assets/css/bootstrap.css');

.container {
    margin-top: 10px;
}

.row {
    display: table-row;
    width: 100px;
}

input[type=text] {
    width: 100%;
}

.cell {
    display: table-cell;
}

http://jsfiddle.net/5pgPY/7/

目标是得到一堆像上面这样的行,其中文本输入的每个实例都有一些可能不同宽度的标签,所以我需要一些方法来确保文本输入所有行。也许我应该放弃使用前置元素并为此使用单独的div?

2 个答案:

答案 0 :(得分:2)

不要看问题来自哪里。无论如何,这对我有用:

@import url('http://twitter.github.com/bootstrap/assets/css/bootstrap.css');

.container {
    margin-top: 10px;
}

.row {
    display: table-row;
    width: 200px;
}

input[type=text] {
    width: 100%;
}

.cell {
    margin-right: 60px;
    float: left;
}

答案 1 :(得分:1)

在你的例子中,你没有在第二个输入中使用input-prepend类,你应该按如下方式编写

<div class="cell input-prepend">
        <input type="number"/>
    </div>

在css中,从输入中删除width = 100%并使用margin-right

    input[type=text] {
       margin-right:10px;

      }

请查看JSfidlle updated JSfiddle prepend

<div class="container">
<div class="row">
    <form class="form-inline">
        <input type="text" class="input-small" placeholder="Email">
        <input type="password" class="input-small" placeholder="Password">
    </form>
    <form class="form-inline">
        <input type="text" class="input-small" placeholder="Email">
        <input type="password" class="input-small" placeholder="Password">
    </form>
</div>
</div>