在 '元素——可以做到吗?

我有兴趣看看是否可以在包裹

目前,Firefox 在

如果我在 中使用内联样式,该行就会消失:

<a href="#" style="text-decoration:none;"><button>

但是,由于我在多个元素上都有

a:before button{
    text-decoration:none !important;
}

这就是

在此处输入图像描述

这是 jsfiddle 上按钮的基本版本(忽略轻微的外观差异):http://jsfiddle.net/Vtjue/2/

有什么想法吗?

I am interested in seeing if I can use the :before pseudo-element on a <a href wrapped around a <button> element?

Currently, Firefox shows a thin blue line behind the <button> element - this is due to it being wrapped in an <a href.

If I use an inline style within the <a href the line goes away:

<a href="#" style="text-decoration:none;"><button>

However, since I have <button> elements on multiple pages, I want to target them using CSS if possible (and I don't particularly want to go and add a class to all the <a href that are wrapping the <button>'s on the site). This is where I was thinking the :before pseudo-element would come in handy but it doesn't seem to work:

a:before button{
    text-decoration:none !important;
}

This is how the <button>'s display in Firefox, see the blue default text-decoration applied to the <a href. The reason it is showing up only on the right hand side is because a class of margin-left:5px is applied to the <button> element:

enter image description here

Here's a basic version of the buttons up on jsfiddle (ignore slight appearance differences): http://jsfiddle.net/Vtjue/2/

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小嗷兮 2024-10-24 17:13:32

:before:after 选择器指的是独立于 DOM 存在并由浏览器动态渲染的生成元素。这意味着您不使用它们来遍历 HTML 结构。

由于 CSS 选择器的性质,您无法选择包含 buttona,只能选择相反的方式(button 包含在 button 中) >a)。恐怕您唯一的选择是使用类,或者将您的按钮a移开,因为它们在语义上不属于那里。

The :before and :after selectors refer to generated elements that exist separately from the DOM and are rendered by the browser on the fly. That means you don't use them to traverse your HTML structure.

Due to the nature of CSS selectors, you cannot select an a that contains a button, only the other way around (button contained by a). I'm afraid your only options are to use a class, or move your buttons away from your a because they semantically don't belong there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文