CSS可以选择具有特定内容的元素吗? [英] Can CSS select elements with specific content?
问题描述
可能重复:
CSS 3 content selector?
我想知道,使用CSS选择一个基于其内容的元素?
我意识到我可以使用这样的东西:
.this [href =./ foo.php] {
/ *和样式... * /
}
但是有一种基于内容选择的方法吗?
我有这个:
< p> [续]< / p&
如何根据内容选择, code>,如果我可以?
不,不是CSS,真的不应该。如果你正在创建一个继续按钮,链接或其他:指定类,也许是ID,甚至使用一个属性,并选择它。
不要说, 不向此链接添加类或某种标识,使其看起来像文档中的常规文本,可能会删除其某些语义含义。给它一个单独的类,使它脱颖而出。如果我给一个链接类按钮,使其脱离页面上的其余链接,说我是一个按钮,而不只是一个普通的链接。基于内容选择不做任何排序;它只是另一个链接。Possible Duplicate:
CSS 3 content selector?
I was wondering, is it possible to select an element based on its content with CSS?
I realize I can use something like this:
.this[href="./foo.php"] {
/* And the styles... */
}
But is there a way to select based on inner content?
So if I have this:
<p>[ Continued ]</p>
How can I select it based on it's content, [ Continued ]
, if I can?
No, not with CSS, and there really should never be a need too. If you're making a "Continued" button, link, or whatever: specify a class, maybe an ID, or even use an attribute, and select it. There really is no need for a content selector with how many options you already have.
Not to mention, not adding a class or some kind of identification to this link makes it look like regular text within the document, possibly removing some of its semantic meaning. Giving it a separate class makes it stand out. If I give a link the class "button," that makes it stand out from the rest of the links on the page, saying "I'm a button, not just an ordinary link." Selecting based on the content does nothing of the sort; it's just another link.
这篇关于CSS可以选择具有特定内容的元素吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!