Can CSS select elements with specific content? [duplicate]

孤人 提交于 2019-12-02 09:54:41

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/9170940/can-css-select-elements-with-specific-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!