我可以使用link_to链接图像和文本 [英] Can I use link_to to link an image and a text

查看:82
本文介绍了我可以使用link_to链接图像和文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我正在使用 font-awesome-rails gem。我已经很习惯在Rails外部使用字体了,但是我想它在Rails社区中并不那么受欢迎。

Well, I am using "font-awesome-rails" gem. I am pretty much used to font-awesome outside Rails, but I guess it's not that popular among Rails community.

一旦安装,它将使用该格式创建图标

Once installed, it creates icons using the format

<i class="nameoftheicon"> </i>

我想到了将其用作网站徽标,其中包括font-awesome和一些文字。所以我尝试了:

I thought of using it for my site logo, which would consist of the icon from font-awesome and some text. So I tried:

<%= link_to "", root_path, class: "icon-puzzle-piece icon-2x" %>
<%=  link_to "My site", root_path, id: 'logo'  %>

它有效,但是当我将鼠标悬停时,它们充当两个不同的元素。

It works, but when I hover, they act as two different elements.


  1. 在单个< a>下合并图像和文本的Rails方法是什么? 标签。

有什么流行的Rails替代字体可真棒?

And is there any popular Rails alternative to font-awesome?


推荐答案

将一个块传递到 link_to ,该块将被链接

Pass a block to link_to and the block will be linked

<%= link_to path, id: "logo" do %>
  <i class="icon-puzzle-piece icon-2x"></i>
  My Super Site
<% end %>

这篇关于我可以使用link_to链接图像和文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆