【问题标题】:add glyphicon to rails link_to helper and disable effects when hovering将 glyphicon 添加到 rails link_to helper 并在悬停时禁用效果
【发布时间】:2016-03-02 02:46:18
【问题描述】:

我正在尝试设置我的 link_to 助手的样式。我想添加一个图标而不是链接并禁用所有效果。我遵循了这种方法Remove underline from link within hyperlinked div,但它对我不起作用,每当我将鼠标悬停在图标上时它就会消失,这不是我想要的。这是我到目前为止所拥有的。

<div id = "owner-icons">
<%= link_to  product, method: :delete, data: { confirm: 'Are you sure?' }  do %>    
<span class="glyphicon glyphicon-trash"></span> 
</div>
<% end %>

bootstrap.css

div.owner-icons a {text-decoration:none;}

是否也可以更改图标的颜色?

【问题讨论】:

  • 你可以通过添加css颜色属性来改变图标的​​颜色。 或 div.owner-icons span {color:red !important;}
  • 谢谢我能改变颜色。
  • 好的,很高兴听到。您还可以通过更改父母颜色来更改引导程序中的颜色。请对我的答案投票))

标签: html css ruby-on-rails twitter-bootstrap


【解决方案1】:

您只需将glyphicon 添加到您的链接中,如下所示:

查看(帮我改一下your_url

<div id="owner-icons">
  <%= link_to  '', your_url, method: :delete, data: { confirm: 'Are you sure?' }, class: 'glyphicon glyphicon-trash' %>
</div>

风格

#owner-icons a {
  color: red; # your custom color
  text-decoration: none;
}

顺便说一句,在您当前的代码中存在一些问题:

  • owner-iconsid 而不是 class,所以你的 css 将无法工作
  • &lt;/div&gt; 我认为结束标签不在正确的位置

更新

为链接添加悬停样式:

  • 如果您使用的是 scss

    #owner-icons a {
      color: red; # your custom color
      text-decoration: none;
      &:hover {
        background: transparent; # Your custom background
      }
    }
    
  • 或者一个普通的css

    #owner-icons a {
      color: red; # your custom color
      text-decoration: none;
    }
    #owner-icons a:hover {
      background: transparent; # Your custom background
    }
    

【讨论】:

  • 它改变了颜色,但是当我将鼠标悬停在它上面时,它的背景现在变成黑色,这意味着 text-decoration: none;我猜不工作?
  • 你可以在你的 CSS 中添加悬停样式,查看我的更新!
猜你喜欢
  • 2014-01-08
  • 1970-01-01
  • 1970-01-01
  • 2016-08-31
  • 2018-11-18
  • 2015-01-01
  • 2017-12-26
  • 1970-01-01
  • 2014-11-08
相关资源
最近更新 更多