如何在Ruby on Rails中设置图片标签
我有一个图像标签,如下所示:
<%= image_tag @user.photo.url(:large) %> 我怎样才能边框颜色样式在CSS中的一侧? 什么html会产生?
添加一个类或ID到你的image_tag:
 <%= image_tag @user.photo.url(:large), :class => "style_image" %> 
然后使用CSS来devise它:
 .style_image { border-right: 1px solid #000; } 
通过使用“样式”选项:
 <%= image_tag @user.photo.url(:large), :style => "border: 1px solid red" %> 
有关更多信息,请查看API。
你也可以给内联风格
 <%= image_tag @user.photo.url(:large), :style => "float :left;border 1px solid #00000;" %> 
尝试一下…..
这是一个简单的方法来做到这一点。
 <%= image_tag("example.png", :style => 'border-right: 1px solid #000;')%> 
对于在Google上遇到此问题的其他人。 如果以不同的方式使用图片标签,您仍然可以添加css类,但它只是不同的语法。 有时您需要使用外部服务器。 (在Heroku上部署=> Amazon S3)
 <%= image_tag("https://s3-us-west-2.amazonaws.com/mybucketname/user_photo.png", class: "style_image") %> 
在更新版本的Rails中,有一个“更好”的方法:
 <%= image_tag('filename_in_public_folder', alt: 'Description', style: 'display: block; margin: auto; width: 40%;')%> 
jquery不会改变图像。 这是我的脚本
 $(document).ready(function() { $('img').click(function(e) { var newclass = $(this).attr("id"); var oldclass = $("product_image_container_show image-center").attr('Class'); $("#product_image_container_show image-center").fadeOut(function(){ $("#product_image_container_show image-center").removeClass(oldclass).addClass(newclass).fadeIn('slow'); }) }) 
});