【问题标题】:How to change the color of link button in .erb template如何更改.erb模板中链接按钮的颜色
【发布时间】:2014-08-28 13:59:09
【问题描述】:

我想更改 erb 模板中“探索”和“提交您的项目”按钮的颜色。目前它们是蓝色的。如果我应该使用 div 来执行此操作,或者还有其他方法吗

<div id="header">
     <%= link_to 'Explore', explore_path %>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
     <%= link_to 'Submit Your Project', submit_path %>

      <div class="wrapper clearfix">
        <h1 id="lockitron_header"><a href="/"><%= Settings.product_name %></a></h1>
      </div>
    </div>

【问题讨论】:

  • &amp;nbsp;s 的那些人是怎么回事?是否为元素添加额外的宽度?因为这就是 css 的用途。
  • 你需要写css样式表。这不是 ruby​​ on rails 问题。
  • Max Williams : &nbsp 是用来创造空间的。有没有替代品?

标签: html css erb


【解决方案1】:

只需给你的锚定 class 或 id,然后使用 css 给它们不同的颜色

<%= link_to 'Explore', explore_path, class: "black" %>
<%= link_to 'Submit Your Project', submit_path, class: "black" %>

在css中

.black {color: #000;}

这是非常基本的 CSS 和 HTML 您应该查看 CSS 和 HTML

【讨论】:

    【解决方案2】:

    将style 用于内联css

    <%= link_to 'Explore', explore_path, style: "color: red;" %>
    

    或使用class

    <%= link_to 'Explore', explore_path, class: "link-color" %>
    

    在样式表中

    .link-color{
      color: "red";
    }
    

    【讨论】:

    • 通过类和相应的样式表来做会更好。当您需要数据驱动的样式时保存样式标签。
    • @MaxWilliams 是的,我现在已经编辑了答案,它告诉我们如何根据需要使用两者。
    猜你喜欢
    • 2014-05-23
    • 2013-10-16
    • 1970-01-01
    • 2013-11-29
    • 1970-01-01
    • 2020-12-11
    • 1970-01-01
    • 1970-01-01
    • 2021-12-22
    相关资源
    最近更新 更多