2013-02-17 63 views
2

我想把兩個輸入元素彼此相鄰,與第一個輸入前面的項目,使用顯示:表格樣式。但是,這導致第二個輸入元素與第一個輸入元素重疊。我試過使用框大小:沒有運氣的邊框。看起來問題是,我限制了父div的寬度,然後將輸入元素的寬度設置爲100%,以便填充父項,但這根本不起作用。這裏是一個的jsfiddle例如:Twitter引導 - 預置的輸入元素重疊時,彼此相鄰

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/

的目標是讓上面一堆像行的在文本輸入的每個實例有一些標籤可能不是相同的寬度,所以我需要一些方法來確保文本輸入全部排隊。也許我應該放棄使用prepended元素併爲此使用單獨的div?

回答

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; 
} 
+0

嗯,邊緣正確的加入工作,我認爲這可能是適當的解決方案。 – Ibrahim 2013-02-17 07:45:30

+0

即使它在這種情況下工作,我不知道它是一種比一般解決方案更多的解決方法... – 2013-02-17 07:51:00

+0

是的,這是一種解決方法,但它比其他解決方案更爲理智。雖然我真的很想讓這個應用程序做一些極端的事情,並隱藏輸入字段,並將內容鏡像到一個div做一些欺騙,因爲調整和定位它們真的很煩人。 – Ibrahim 2013-02-17 08:01:25

1

在你的榜樣,你還沒有使用的輸入,前置級的第二輸入,你應該從輸入如下

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

而且在CSS刪除寬度= 100%寫和使用保證金右

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> 
+0

沒有雅檢查的jsfiddle – Shail 2013-02-17 07:21:52

+0

我需要他們旁邊的是對方,你錯過了這個問題的那部分還是我失去了一些東西?哦,這取決於我的瀏覽器的寬度...我實際上不需要這些,而且我也不知道如何堆疊多行,所以我認爲這不會解決問題。 – Ibrahim 2013-02-17 07:35:07

+0

他們在我的小提琴中彼此相鄰.. – Shail 2013-02-17 07:35:46