문제

I'm trying to put two input elements next to each other, with a prepended item on the first input, using display:table styles. However, this results in the second input element overlapping the first. I've tried using box-sizing: border-box with no luck. It seems like the problem is that I'm constraining the width of the parent div and then setting the width of the input element to 100% so that it fills up the parent, but this doesn't work at all. Here is a JSfiddle example:

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/

The goal is to get a bunch of rows like the above where each instance of the text input has some label which might not be the same width, so I need some way to make sure that the text inputs all line up. Maybe I should just give up on using the prepended element and use a separate div for that?

도움이 되었습니까?

해결책

Don't see where the problem comes from. Anyways, that worked for me:

@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;
}

다른 팁

In your example you have not used the input-prepend class in the second input , you should write it as follows

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

And in css remove width=100% from input and use margin-right

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

      }

Can you please check the 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>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top