2015-05-13 99 views
1

我的表单中有两个按钮,我使用CSS工作表来布置表格,我想要最后一行中的按钮,但我希​​望它们并排放置。使用rails代码,css和html对齐按钮

我当前的代码看起来像

<button><%= link_to "Edit", edit_user_path(u.id), { :method =>get } %></button> 
<button><%= link_to "Delete", user_path(u.id), { :method => delete, :class=>destroy, data: {confirm: 'Are you sure?' } %></button> 

enter image description here

如果我将其更改为:

<button><%= button_to "Edit", edit_user_path(u.id), { :method =>get } %></button> 
<button><%= button_to "Delete", user_path(u.id), { :method => delete, :class=>destroy, data: {confirm: 'Are you sure?' } %></button> 

enter image description here

按钮结束并排,但与按钮标签中的额外按钮。 如果我将其更改为:

<td><%= button_to "Edit", edit_user_path(u.id), { :method =>get } %> 
<%= button_to "Delete", user_path(u.id), { :method => delete, :class=>destroy, data: {confirm: 'Are you sure?' } %></td> 

enter image description here

的按钮是在同一行,但水平神韵:。

有没有办法让这两个按钮正确显示在列的中心?也许可以在CSS中添加一些内容,告诉它如何处理按钮调用?

+1

我不明白的问题......他们在你的第一个图像中并排是不是他们? – Lee

+1

他们并肩作战,我期待着看看是否有更好的方法来做到这一点,或者让他们一致。 –

+0

问题是'button_to'没有创建'

回答

2

包裹在一个div按钮,如下所示:https://jsfiddle.net/5th07vq6/

HTML:

<div class="center"> 
    <button>Edit</button> 
    <button>Delete</button> 
</div> 

CSS:

.center { 
    width: 50%; 
    margin: 0 auto; 
}