简体   繁体   English

为image_tag添加标题Ruby on Rails

[英]Adding caption to image_tag Ruby on Rails

I was wondering how to add a caption to my image_tag in rails. 我想知道如何在rails中为我的image_tag添加标题。 Here is what it loos like: 这是它喜欢的东西:

<%= image_tag "img1.jpg", :class => "rounded float-left", :height => '400px' %>

Is there anyway to add a caption beneath this picture that I have. 反正在这张图片下方添加了标题。 Thanks :) 谢谢 :)

There's no Rails helper for this that I'm aware of, but something like this should give you a caption below the image: 我知道没有Rails助手,但是这样的东西应该给你一个图片下方的标题:

<figure>
    <%= image_tag "img1.jpg", :class => "rounded float-left", :height => '400px' %>
    <figcaption>Caption goes here</figcaption>
</figure>

You can add a title with :title => "title" if you consider that a caption. 如果考虑标题,可以添加标题:title => "title" If not, it's best to create a helper that outputs the image with a text centered and aligned immediately below. 如果没有,最好创建一个帮助器,输出图像,文本居中并在下方对齐。

Example: 例:

<div class="figure">
  <img src=""/>
  <p class="caption">
    <span class="caption-text">Some caption of any length</span>
   </p>
</div>

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

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