基于样式HTML元素的标题使用CSS [英] Style HTML element based on its title using CSS
问题描述
是否可以只使用标题作为唯一标识符将样式应用于HTML元素?例如:
< div class =my_class>
< a href =some sitetitle =MyTitle>我的链接< / a>
< / div>
我想写一个规则,仅适用于class my_class的div中的link元素,链接标题MyTitle。
我没有能力更改页面布局,但是,我可以使用自动包含的自定义CSS文件。
谢谢
确定是使用所谓的属性选择器;这些都是CSS2的一部分。在特定情况下,您可以使用:
div.my_class a [title =MyTitle] {color:red; }
您可以在这里阅读更多有关属性选择器的信息: http://www.w3.org/TR/CSS2/selector.html#attribute-selectors p>
Is it possible to apply a style to an HTML element using only its title as a unique identifier? For example:
<div class="my_class">
<a href="some site" title="MyTitle">My Link</a>
</div>
I would like to write a rule that will apply only to link element within a div of class my_class and the link title MyTitle.
I do not have the ability to change page layout, however, I can use a custom CSS file that is included automatically.
Thank you
It sure is, using what's called attribute selectors; these are part of CSS2. In your particular case, you'd use:
div.my_class a[title="MyTitle"] { color: red; }
You can read more about attribute selectors here: http://www.w3.org/TR/CSS2/selector.html#attribute-selectors
这篇关于基于样式HTML元素的标题使用CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!