使用 Rails 3 以圆形显示图像
Displaying Image in round shape using Rails 3
我想使用 RoR 以圆形显示图像。请看我下面的图片标签,帮我把它变成圆形。
<%= image_tag(current_user.picture_url, :width => 70,:height => 60 ) %>
不要对 "current_user.picture_url" 行感到困惑,它正在从数据库中获取图像 url。
Rails 没有任何火箭科学。它是 css
的一部分。您可以在 image_tag
中定义 class
并使用您想要的任何样式编写 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
中使用,因为您可以在应用程序的任何地方使用此 class 来应用相同的样式。
我想使用 RoR 以圆形显示图像。请看我下面的图片标签,帮我把它变成圆形。
<%= image_tag(current_user.picture_url, :width => 70,:height => 60 ) %>
不要对 "current_user.picture_url" 行感到困惑,它正在从数据库中获取图像 url。
Rails 没有任何火箭科学。它是 css
的一部分。您可以在 image_tag
中定义 class
并使用您想要的任何样式编写 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
中使用,因为您可以在应用程序的任何地方使用此 class 来应用相同的样式。