如何在链接中放置图片? [英] How to place an image inside of a link?

查看:170
本文介绍了如何在链接中放置图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试一些非常简单的操作,在链接中我希望包含文本和图像.

I'm trying something really simple, inside a link I want there to be text and an image.

= link_to 'NVidia Graphics', inventory_url, class: 'lato' do
  = image_tag 'list-highlighter.png'

我希望输出为:

<a href="/inventory">
  NVidia Graphics
  <img src="list-highlighter.png" />
</a>

如何使用Slim做到这一点?我当前的代码导致网站崩溃.

How can I achieve this using Slim? My current code causes the website to crash.

" http://foobar.com/inventory 的未定义方法`stringify_keys':String

undefined method `stringify_keys' for "http://foobar.com/inventory":String

推荐答案

= link_to inventory_url, class: 'lato' do
  | NVidia Graphics
  = image_tag 'list-highlighter.png'

我认为这应该有效..苗条的语法不是100%.将某些内容包装为块时,link_to不应包含任何内容,也就是说,应紧随其后的是url.其中的所有内容将由<a>标签输出包装.对于非苗条的人,这看起来像

I think that should work.. just not 100% about the slim syntax. link_to shouldn't have any content when wrapping something as a block -- that is, it should be immediately followed by its url. All the content inside will be wrapped by the <a> tag output. For non-slim, this would look like

<%= link_to inventory_url, class: 'lato %>
  NVidia Graphics
  <%= image_tag 'list-highlighter.png' %>
<% end %>

这篇关于如何在链接中放置图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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