2017-03-23 55 views
0

我想對齊文本輸入的權利,由於某種原因,它沒有這樣做。在td中將文本輸入對齊到右邊?

我在<td>

使用style="text-align: right"見例如:

https://jsfiddle.net/DTcHh/31200/

代碼

<table class="table"> 
    <thead> 
    <tr> 
     <th>Field 1</th> 
     <th style="text-align:right">Field 1</th> 
    </tr> 
    </thead> 
    <tbody> 
    <tr> 
     <td>Text 1</td> 

     <td style="text-align: right"> 
     <div class="form-group" style="text-align: right"> 
      <input style="width:60px" type="number" class="form-control" value="test"> 
     </div> 
     </td> 
    </tr> 
    </tbody> 
</table> 
+0

你想要的「​​文本1」對齊到正確的?或''? –

+0

可能的重複http://stackoverflow.com/questions/18086468/align-text-to-right-in-td-tag –

+0

可能重複[對齊文本到正確的td標籤](http://stackoverflow.com /問題/ 18086468 /對齊文本到右功能於TD-標籤) –

回答

2

需要沒有額外的CSS只是使用引導pull-right

https://jsfiddle.net/cp1tvuj3/

<div class="form-group"> 
      <input style="width:60px" type="number" class="form-control pull-right" value="test"> 
</div> 

Updated fiddle

text-right將無法​​工作,因爲form-controldisplay: block

0

好像只是增加float: right;開了竅,看到

url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css'); 
 
body { 
 
    margin: 10px; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/> 
 
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> 
 
<table class="table"> 
 
    <thead> 
 
    <tr> 
 
     <th>Field 1</th> 
 
     <th style="text-align:right">Field 1</th> 
 
    </tr> 
 
    </thead> 
 
    <tbody> 
 
    <tr> 
 
     <td>Text 1</td>  
 
     <td style="text-align: right"> 
 
     <div class="form-group" style="text-align: right; float:right"> 
 
      <input style="width:60px" type="number" class="form-control" value="test"> 
 
     </div> 
 
     </td> 
 
    </tr> 
 
    </tbody> 
 
</table>

1

inline-block的添加到您的div元素,默認情況下,DIV是塊元素,因此需要其母公司的整個寬度

<div class="form-group" style="text-align: right;display:inline-block;"> 
      <input style="width:60px" type="number" class="form-control" value="test"> 
</div> 

https://jsfiddle.net/RACCH/y9fvo4dj/

0

您需要添加引導類即ie。 「右拉」 發現代碼小提琴:

`https://jsfiddle.net/DTcHh/31204/e`