繁体   English   中英

如何删除 html 超链接“a”标签的默认链接颜色?

[英]How do I remove the default link color of the html hyperlink 'a' tag?

默认链接颜色为蓝色。 如何删除 html 超链接标签<a>的默认链接颜色?

继承值

a { color: inherit; } 

... 将导致元素呈现其父元素的颜色(这就是我认为您正在寻找的)。

现场演示如下:

 a { color: inherit; }
 <p>The default color of the html element is black. The default colour of the body and of a paragraph is inherited. This <a href="http://example.com">link</a> would normally take on the default link or visited color, but has been styled to inherit the color from the paragraph.</p>

尝试这样的事情:

a {
    color: #0060B6;
    text-decoration: none;
}

a:hover {
    color:#00A0C6; 
    text-decoration:none; 
    cursor:pointer;  
}

如果text-decoration不起作用,请将其更改为:

text-decoration: none !important;

!important规则会覆盖text-decoration属性的所有其他样式。 你可以在这里阅读更多关于它的信息。

如果您不想看到浏览器提供的下划线和默认颜色,可以将以下代码保留在 main.css 文件的顶部。 如果您需要不同的颜色和装饰样式,您可以使用以下代码片段轻松覆盖默认值。

 a, a:hover, a:focus, a:active {
      text-decoration: none;
      color: inherit;
 }
.cancela,.cancela:link,.cancela:visited,.cancela:hover,.cancela:focus,.cancela:active{
    color: inherit;
    text-decoration: none;
}

我觉得有必要发布上面的 class 定义,SO上的许多答案都错过了一些状态

这也是可能的:

a {
  all: unset;
}

unset:此关键字指示将应用于元素或元素父级的所有属性更改为其父值(如果它们是可继承的,则更改为初始值)。 unicode-bidi 和方向值不受影响。

来源: Mozilla 对所有的描述

只需将其添加到CSS中,

a {
    color: inherit;
    text-decoration: none;
}

就是这样,完成。

您必须使用CSS 这是一个更改默认链接颜色的示例,当链接只是坐在那里时,当它被悬停时,当它是一个活动链接时。

 a:link { color: red; } a:hover { color: blue; } a:active { color: green; }
 <a href='http://google.com'>Google</a>

您可以使用随 CSS 2.0 引入的系统颜色 (18.2)值,但在 CSS 3 中已弃用

a:link, a:hover, a:active { color: WindowText; }

这样,您的锚链接将与该系统上的普通文档文本具有相同的颜色。

当我使用 Bootstrap 4 开发 Rails 6 应用程序时,我遇到了这个挑战。

我的挑战是我不希望这种样式覆盖应用程序中的默认链接样式。

所以我创建了一个名为custom.csscustom.scssCSS文件。

然后定义了一个新的CSS 规则,具有以下属性

.remove_link_colour {
  a, a:hover, a:focus, a:active {
      color: inherit;
      text-decoration: none;
  }
}

然后我在需要覆盖默认链接样式的任何地方调用此规则。

<div class="product-card__buttons">
  <button class="btn btn-success remove_link_colour" type="button"><%= link_to 'Edit', edit_product_path(product) %></button>
  <button class="btn btn-danger remove_link_colour" type="button"><%= link_to 'Destroy', product, method: :delete, data: { confirm: 'Are you sure?' } %></button>
</div>

这解决了覆盖默认链接样式的问题,并仅在我调用CSS 规则的地方删除按钮中的默认颜色hover焦点活动样式。

就这样。

我希望这有帮助

a:link{color:inherit;}

这是简单的一行可以为你做所有的事情<3

我也想删除标签的默认蓝色链接颜色。 当我使用 bootstrap 版本 5 时,我决定在 bootstrap 文档中寻找解决方案。 我搜索了“链接颜色”,结果是这个链接:“https://getbootstrap.com/docs/5.0/helpers/colored-links/”

bootstrap 5.0 版有一个 class 来自定义链接 colors,我发现这非常有帮助,而且我能够毫不费力地更改“a”标签的默认蓝色。

希望这会有所帮助。

<style>
a {
color:      ;
}
</style>

此代码将颜色从默认更改为样式中指定的颜色。 使用:hover,您可以更改 hover 上的默认文本颜色。

这将起作用

    a:hover, a:focus, a:active {
        outline: none;
    }

这样做是删除所有三个伪类的轮廓。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM