【问题标题】:What to do when link_to is overriding the css class that I've applied?当 link_to 覆盖我应用的 css 类时该怎么办?
【发布时间】:2016-01-11 22:26:03
【问题描述】:

我在使用 link_to 和 image_tag 方法和 CSS 时遇到了严重问题。无论出于何种原因,我都无法使用我编写的 CSS 来保持我的头像的圆形形状。当我只使用 image_tag 时,它工作得很好。当我同时使用 link_to 和 image_tag 时,它会将图像变回正方形。

这是链接

<%= link_to(image_tag(current_user.avatar_url(:thumb)), current_user, class: 'round-image-50', title:  "Profile", style: '') %>

.round-image-50 {
  background-color: white;
  border: 1px solid #d9d9d9;
  border-radius: 25px;
  -moz-border-radius: 25px;
  -webkit-border-radius: 25px;
  height: 50px;
  width: 50px;
  overflow: hidden;
  text-align: center;
  img {
    width: 100%
  }
}

你能帮我弄清楚为什么它会覆盖为它编写的 CSS 属性吗?

【问题讨论】:

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


    【解决方案1】:

    我必须在方法块的 image_tag 部分中定义类。

    <%= link_to(image_tag(current_user.avatar_url(:thumb), class: 'round-image-50'), current_user, title:  "Profile", style: '') %>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-20
      • 2011-04-30
      • 2014-04-24
      • 1970-01-01
      • 2015-04-15
      • 2019-08-17
      • 1970-01-01
      相关资源
      最近更新 更多