0

我有一个似乎适应给定列中最长文本字符串的表。我在每一行都有选择标签,这些标签似乎弄乱了显示。表格中添加了一个额外的列,并且右侧的边框未显示。如果我缩小选择标签的大小,表格格式正确,但我希望表格符合下一列中最大选择标签和最大按钮的大小。谢谢。这是代码:

<table class="table table-bordered table-condensed">
<thead>
<tr>
    <th>Position</th>
    <th>Allocation</th>
    <th>Action</th>
</tr>
</thead>

<% position_map = @cabinet.cabinet_position_map %>
<% @cabinet.cabinet_type.usize.downto(1) do |i| %>
<tr>
    <td>Slot: <%= i %></td>
    <% if position_map[i].nil? %>
        <% cabinet_device_selection = @cabinet.devices_to_fit(position_map, i) %>
        <% @selection_list = [ "Power", "I/O", "Interface", "Unusable", "Other", "Missing", "Reserve" ] %>
        <% cabinet_device_selection.each do |device| %>
            <% @selection_list << device.name %>
        <% end %>
        <% if position_map[i].nil? %>
                <%= form_tag( {:controller => :cabinets, :action => :update_device_position, :position => i , :id => @cabinet.id } , { :method => 'get', :class => "form-search" }) do %>
                    <td>
                        <%= select_tag :position_name, options_for_select(@selection_list) %>
                    </td>
                    <td>
                        <%= hidden_field_tag 'position', i %>
                        <%= submit_tag "Add" , :class => "btn" %>
                    </td>
                <% end %>
        <% end %>               
    <% else %>
        <% position_map[i].each do |cabinet_item| %>
            <td>
                <%= cabinet_item.name %>&nbsp;
            </td>
            <td>
                <%= link_to "Remove", { :controller => :cabinets, :action => :remove_cabinet_position, :id => @cabinet.id, :position => i}, :class => "btn btn-danger" %>
            </td>
        <% end %>
    <% end %>   
</tr>
<% end %>
</table>

这是输出的样子:

格式错误的图像

4

1 回答 1

0

看来您正在使用 Bootstrap。

所以,要改变 select_tag 的宽度,你可以简单地做。

    <%= select_tag :position_name, options_for_select(@selection_list), :class => "span1" %>

或者,如果您想设置自定义宽度,请在您的 CSS 中添加一个类。

    .option-small {
       width: 100px !important;
    }

然后使用

    <%= select_tag :position_name, options_for_select(@selection_list), :class => "option-small" %>
于 2013-03-09T10:56:49.143 回答