【问题标题】:How to set inline rails image_tag as background image?如何将 inline rails image_tag 设置为背景图像?
【发布时间】:2015-10-21 02:55:38
【问题描述】:
 =image_tag "#{user.image}", :class => "user-photo"

上面的这段代码设置了图像,但我希望所有图像都是圆形的。如果用户上传尺寸错误的照片,将边框半径设置为 50% 会生成椭圆形照片,而不是圆形照片。

我正在考虑是否可以将内嵌的内插图像设置为背景图像,然后我可以将它们全部设为圆形。

【问题讨论】:

    标签: ruby-on-rails css ruby-on-rails-4


    【解决方案1】:
    .circular {
        width: 300px;
        height: 300px;
        border-radius: 150px;
        -webkit-border-radius: 150px;
        -moz-border-radius: 150px;
        background: url(http://link-to-your/image.jpg) no-repeat;
    }
    

    http://bavotasan.com/2011/circular-images-with-css3/

    【讨论】:

    • 我无法访问 css 中的图片链接,因为它们是上传的用户图片并在 s3 中设置。
    • 你不需要链接,只需在css中将circular类引用到你的图片<div>''s and it should do the trick. Disregard the background:`。
    • 那不会扭曲图像吗?
    • 是的,我很确定这归结为我需要作为背景图像的根本问题。
    • 使用您保存的用户图片的实例变量
    猜你喜欢
    • 2014-06-23
    • 2021-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-05
    • 1970-01-01
    相关资源
    最近更新 更多