使用Rails 3以圆形显示图像

时间:2015-04-07 04:29:36

标签: ruby image ruby-on-rails-3

我想使用RoR以圆形显示图像。请看我的下面的图片标签,并帮助我如何将其转换为圆形。

<%= image_tag(current_user.picture_url, :width => 70,:height => 60 ) %>

不要对这条线感到困惑&#34; current_user.picture_url&#34;它从数据库中获取图像URL。

1 个答案:

答案 0 :(得分:3)

Rails没有任何火箭科学。它是css的一部分。您可以在class中定义image_tag,然后使用您想要提供的样式编写您的CSS。像这样:

<%= image_tag current_user.picture_url ,:class=> "img-circular" %>

并在您的 application.css 或您的视图文件中写下:

<style>  # if you are putting this code in application.css then no need to write <style> tag
.img-circular{
 width: 200px;
 height: 200px;
 background-size: cover;
 display: block;
 border-radius: 100px;
 -webkit-border-radius: 100px;
 -moz-border-radius: 100px;
}
</style>

Working Demo

注意:最好在application.css中使用,因为您可以在应用程序的任何位置使用此类来应用相同的样式。

相关问题