【问题标题】:How to change my link color on Rails code?如何在 Rails 代码上更改我的链接颜色?
【发布时间】:2018-10-08 14:57:06
【问题描述】:

我正在尝试将以下 Rails 链接更改为原色(当前为白色):

<%= link_to 'Edit' %>

【问题讨论】:

标签: css ruby-on-rails colors hyperlink


【解决方案1】:

提供路径后,您可以在链接中添加class

<%= link_to 'Edit', edit_path, class: "a-primary" %>

并为该类添加样式。

.a-primary{
  /* styles for link */
}

【讨论】:

    【解决方案2】:

    如果您的应用程序具有通用样式,则无需定义 CSS 类。只需为 &lt;a&gt; 标签编写 CSS:

    a:link, a:visited {
    background-color: #f44336;
    color: white;
    padding: 14px 25px;
    text-align: center; 
    text-decoration: none;
    display: inline-block;
    }
    
    a:hover, a:active {
      background-color: red;
    }
    

    Ruby 代码

    <%= link_to 'Edit' , '#'%>
    

    Rails 将 link_to 脚本呈现为 HTML 中的普通超链接。

    <a href="#" > Edit</a>
    

    然后浏览器会将样式应用到应用程序中的所有超链接。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-14
      • 1970-01-01
      • 2018-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多