【问题标题】:Overwrite hyperlink style in Rails在 Rails 中覆盖超链接样式
【发布时间】:2012-01-30 23:16:55
【问题描述】:

我使用 Bootstrap 作为我的 CSS 样式。我想将链接伪装成按钮,所以我需要关闭悬停样式:

a:hover {
         color: #00438a;
         text-decoration: underline;

}

我将如何覆盖我的 html 文件中的悬停属性(而不是覆盖已在 Bootstrap 中定义的内容)。

谢谢。

【问题讨论】:

    标签: ruby-on-rails css hyperlink


    【解决方案1】:

    为特定的 id 标签制作样式。

    所以改变:

    a:hover {
         color: #00438a;
         text-decoration: underline;
    }
    

    a#some_id_tag_name:hover {
         color: #00438a;
         text-decoration: underline;
    }
    

    如果你想重用样式,或者创建一个特定的类来覆盖。

    a.some_class_tag_name:hover {
         color: #00438a;
         text-decoration: underline;
    }
    

    【讨论】:

      【解决方案2】:

      您实际上无法“关闭”CSS 样式,您只能将它们显式设置为其他样式(inherit 值是有点的例外)。无论如何,在你的情况下:

      • 在您的链接中添加class
      • 在样式表中为其创建新规则
      • 定义您的风格

      类似:

      .my-class:hover {
            color: {YOUR_COLOR};
            text-decoration: none;
      }
      

      你也可以使用内联样式和!important,如果你真的必须这样做:

      <a style="text-decoration:none !important"></a>
      

      尽可能避免使用第二种方法(即几乎总是)。

      【讨论】:

        猜你喜欢
        • 2013-10-22
        • 2016-03-27
        • 2013-05-06
        • 1970-01-01
        • 2017-08-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多