如何在ONE LINK上禁用链接颜色更改?

时间:2014-12-28 00:04:14

标签: html ruby-on-rails

我有一个按钮,我希望文本字体颜色为红色,但它仍然是灰色的,因为它之前已被点击过。如何禁用此链接的链接颜色更改?

index.html.erb

<button class="button"><%= link_to 'New Value', new_value_path %></button>

values.css.scss

.button {
    padding: 10px 15px;
    background: #4479BA;
    color: #FF0000;
}

scaffolds.css.scss

body {
  background-color: #fff;
  color: #333;
  font-family: verdana, arial, helvetica, sans-serif;
  font-size: 13px;
  line-height: 18px;
}

p, ol, ul, td {
  font-family: verdana, arial, helvetica, sans-serif;
  font-size: 13px;
  line-height: 18px;
}

pre {
  background-color: #eee;
  padding: 10px;
  font-size: 11px;
}

a {
  color: #000;
  &:visited {
    color: #666;
  }
  &:hover {
    color: #fff;
    background-color: #000;
  }
}

div {
  &.field, &.actions {
    margin-bottom: 10px;
  }
}

#notice {
  color: green;
}

.field_with_errors {
  padding: 2px;
  background-color: red;
  display: table;
}

#error_explanation {
  width: 450px;
  border: 2px solid red;
  padding: 7px;
  padding-bottom: 0;
  margin-bottom: 20px;
  background-color: #f0f0f0;
  h2 {
    text-align: left;
    font-weight: bold;
    padding: 5px 5px 5px 15px;
    font-size: 12px;
    margin: -7px;
    margin-bottom: 0px;
    background-color: #c00;
    color: #fff;
  }
  ul li {
    font-size: 12px;
    list-style: square;
  }
}

1 个答案:

答案 0 :(得分:0)

无效 HTML - anchor不能在button内。

您最好的选择是将anchor设置为button

.btn {
  background: #3498db;
  background-image: -webkit-linear-gradient(top, #3498db, #2980b9);
  background-image: -moz-linear-gradient(top, #3498db, #2980b9);
  background-image: -ms-linear-gradient(top, #3498db, #2980b9);
  background-image: -o-linear-gradient(top, #3498db, #2980b9);
  background-image: linear-gradient(to bottom, #3498db, #2980b9);
  -webkit-border-radius: 28;
  -moz-border-radius: 28;
  border-radius: 28px;
  font-family: Arial;
  color: #ffffff;
  font-size: 20px;
  padding: 10px 20px 10px 20px;
  text-decoration: none;
}

.btn:hover {
  background: #3cb0fd;
  background-image: -webkit-linear-gradient(top, #3cb0fd, #3498db);
  background-image: -moz-linear-gradient(top, #3cb0fd, #3498db);
  background-image: -ms-linear-gradient(top, #3cb0fd, #3498db);
  background-image: -o-linear-gradient(top, #3cb0fd, #3498db);
  background-image: linear-gradient(to bottom, #3cb0fd, #3498db);
  text-decoration: none;
}

.btn:active{
  color:red;
}
<a href="" class="btn">I'm a button</a>

使用css3buttongenerator中的样式,添加.btn:active以在点击anchor时添加一些样式并注意{注意color:red)。

或者让buttonanchor - How to create an HTML button that acts like a link?

一样行事

<强>更新

要将它与rails link_to帮助器一起使用,请使用它:

<%= link_to "I'm a button", new_value_path, class: 'btn' %>