简体   繁体   English

将glyphicon添加到rails link_to helper并在悬停时禁用效果

[英]add glyphicon to rails link_to helper and disable effects when hovering

I'm trying to style my link_to helper. 我正在尝试设置link_to助手的样式。 I want to add an icon instead of a link and disable all the effects. 我想添加一个图标而不是一个链接并禁用所有效果。 I followed this method Remove underline from link within hyperlinked div but it did not work for me, whenever I hover over the icon it disappears which is not what I want. 我遵循了此方法, 从超链接div中的链接中删除下划线,但是对我来说不起作用,每当我将鼠标悬停在图标上时,它就会消失,这不是我想要的。 Here's what I have so far. 到目前为止,这就是我所拥有的。

<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 bootstrap.css

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

Is possible to change the color of the icon as well ? 是否可以更改图标的颜色?

You simpy add glyphicon to you link like this: 您简单地将glyphicon添加到您的链接中,如下所示:

View (help me change your_url ) 查看 (帮助我更改your_url

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

Style 样式

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

Btw, in your current code has some problems: 顺便说一句,在您当前的代码中有一些问题:

  • owner-icons is id not class , so your css will not work owner-iconsid不是class ,所以您的CSS将无法工作
  • </div> closing tag isn't in the right place I think </div>我认为关闭标签的位置不正确

Update 更新资料

Add hover style to link: 将悬停样式添加到链接:

  • In case you are using scss 如果您正在使用scss

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

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

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

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