简体   繁体   English

用表格中的提交按钮制作精灵

[英]Making a sprite with a submit button in a table

I want to create two sprite buttons to validate (or not) some requests. 我想创建两个精灵按钮来验证(或不验证)某些请求。

So here is my agreed button : 所以这是我同意的按钮

<div class="validation_button loan_button" id="agreed_loan_button_<%=loan.id%>">
  <% if loan.agreed == true %>
    <div class="icon-agree enabled"></div>
  <% elsif loan.agreed == false %>
    <div class="icon-agree disabled"></div>
  <% else %>
    <%= form_for(loan, remote: true) do |f| %>
      <div><%= f.hidden_field :agreed, value: true %></div>
      <%= image_submit_tag("24px.png", alt: t('button.loan.agree'), title: t('button.loan.agree'), class: "icon-agree active") %>
    <% end %>
  <% end %>
</div>

Where 24px.png is a 24px side size square transparent image. 其中24px.png是边长为24px的正方形透明图像。

And here is where my agree button takes place : 这是我同意按钮发生的地方:

<table class="table table-hover">
  <tbody>
    <tr>
      <th><%= t('product.borrower') %></th>
      <th><%= t('loan.created.since_the') %></th>
      <th><%= t('loan.validation') %></th>
    </tr>
    <% @pending_loans.each do |loan| %>
      <tr id="loan_<%= loan.id %>">
        <td>
          <%= link_to loan.seeker.name, loan.seeker %>
        </td>
        <td>
         <%= I18n.l loan.created_at, format: :only_date %>
        </td>
        <td class="validation">
          <%= render 'loans/buttons/agreed', loan: loan %>
          <%= render 'loans/buttons/refused', loan: loan %>
        </td>
      </tr>
    <% end %>
  </tbody>
</table>

Then here is my css : 然后这是我的CSS

.icon-agree {
  background: url("agree.png");
  display: block;
  width: 24px;

  height: 24px;
  &.enabled {
    background-position: 0 -24px;
  }
  &.disabled {
    background-position: 0 0;
  }
  &.active {
    text-indent: -9999px;
    &:hover {
      background-position: 0 -24px;
    }
    &:active {
      background-position: 0 -48px;
    }
  }
}

When I using my app in a development environment, it renders exactly what I want. 在开发环境中使用我的应用程序时,它可以完全呈现​​我想要的内容。 But if I push it to production, the square transparent image becomes blank and hide the sprite background. 但是,如果我将其投入生产,则正方形透明图像将变为空白并隐藏精灵背景。

Do you have an idea to make this works, and make it more... good practice ? 您是否有一个想法可以使它可行,并使其更多……良好实践?

It looks like you're using SASS/SCSS. 看来您正在使用SASS / SCSS。 Have you verified that your SCSS files are properly compiled in production? 您是否已验证SCSS文件已在生产环境中正确编译? Are you using anything (eg, Compass) to assemble your sprites? 您是否使用任何东西(例如,指南针)来组装精灵?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM