从下面的屏幕截图中可以看出,链接未在 div 的底部对齐。如何对齐 div 底部的修改,删除,添加购物车按钮。注意我没有使用表格。
.bottomaligned {position:absolute; bottom:0; margin-bottom:7px; margin:7px;}
.fixedheight { height: 208px; position:relative; border:1px solid; margin:7px;}
这里粘贴了模板的相关位,这些位用于渲染截面如下所示的页面。请注意,使用css class =“bottomaligned”仍然没有对齐链接。即使我将 width:300px; 添加到css类 .fixedheight ,它们仍然没有对齐。
<div class="row">
<% @products.each do |product| %>
<div class="col-lg-3 col-sm-4 col-6 fixedheight ">
<div class="bottomaligned">
<%= link_to 'edit', edit_product_path(product), class: "btn btn-danger" %>
<%= button_to "Delete", product, data: {confirm: 'Are u sure?'}, method: :delete, class: "btn btn-danger" %>
<%= button_to "Add to cart", order_items_path(product_id: product) %>
</div>
<hr>
</div><!-- /.col-lg-3 -->
<% end %>
</div><!-- /.row -->
屏幕截图:
答案 0 :(得分:20)
我解决了。查看新屏幕截图。我通过添加3个不同的css类来实现它: bottomaligned , bottomright 和 bottomleft ,因此每个链接现在都有不同的css类。
.bottomaligned {position:absolute; bottom:0; margin-bottom:7px; left: 0;}
.bottomright {position:absolute; bottom:0; margin-bottom:7px; margin:7px; right: 0;}
.bottomleft {position:absolute; bottom:0; margin-bottom:7px; left: 100px;}
.fixedheight { height: 200px; width: 243px; position:relative; border:1px solid;}
这就是模板现在的样子:
<div class="col-lg-3 col-sm-4 col-6 fixedheight ">
<div>
<div >
<span class="bottomleft"><%= link_to 'edit', edit_product_path(product), class: "btn btn-danger" %></span>
<span class="bottomright"><%= button_to "Delete", product, data: {confirm: 'Are u sure?'}, method: :delete, class: "btn btn-danger" %></span>
<span class="bottomaligned"> <%= button_to "Add to cart", order_items_path(product_id: product) %></span>
</div>
<hr>
</div><!-- /.col-lg-3 -->
新截图: