I was wondering how to add a caption to my image_tag in rails. 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:
<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. 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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.