我可以选择< a>吗?只有当周围没有文字时? [英] Can I select <a> only when there's no text around it?

查看:46
本文介绍了我可以选择< a>吗?只有当周围没有文字时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想选择锚标记,仅当它们完全独立时,这样我才能使锚标记看起来像按钮,而不会导致句子中的锚看起来像按钮。我不想添加额外的类,因为这是在CMS中进行的。

I would like to select anchor tags only when they're completely by themselves, that way I can make those look like buttons, without causing anchors within sentences to look like buttons. I don't want to add an extra class because this is going within a CMS.

我本来是尝试这样做的:

I originally was trying this:

article p a:first-child:last-child {
    background-color: #b83634;
    color: white;
    text-transform: uppercase;
    font-weight: bold;

    padding: 4px 24px;
}

但这不起作用,因为文本内容不被视为:第一个孩子:最后一个孩子

But it doesn't work because text content isn't considered as criteria for :first-child or :last-child.

我想匹配

<p><a href='#'>Link</a></p>

但不是

<p><a href='#'>Link</a> text content</p>

<p>text content <a href='#'>Link</a></p>

CSS可能吗?

推荐答案

简单的答案是:不,您不能

此处此处此处,没有适用于文本节点的CSS选择器。

As explained here, here and here, there is no CSS selector that applies to the text nodes.

如果可以使用jQuery,请使用看看包含选择器

If you could use jQuery, take a look at the contains selector.

这篇关于我可以选择&lt; a&gt;吗?只有当周围没有文字时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆