【发布时间】:2014-01-25 04:37:04
【问题描述】:
我的想法与content 属性的attr() 值一致。
我想到的代码类型的一个例子是:
.class[attribute=attr(attribute)]:first-of-type .child{
color: green;
}
我知道这可以在 jQuery 中完成,但由于我无法操作正在重新设置样式的页面,因此最好使用 CSS 方法。
编辑:由于这可能会混淆我想要的内容,因此我将为我想要选择的内容提供一些示例 HTML。
<div class="class" attribute="mrmcpowned">
<span class="child">Test1</span>
</div>
<div class="class" attribute="mrmcpowned">
<span class="child">Test2</span>
</div>
<div class="class" attribute="mrmcpowned">
<span class="child">Test3</span>
</div>
<div class="class" attribute="mrmcpowned">
<span class="child">Test4</span>
</div>
<div class="class" attribute="friend">
<span class="child">Test1</span>
</div>
<div class="class" attribute="friend">
<span class="child">Test2</span>
</div>
<div class="class" attribute="friend">
<span class="child">Test2</span>
</div>
<div class="class" attribute="friend">
<span class="child">Test3</span>
</div>
<div class="class" attribute="otherfriend">
<span class="child">Test1</span>
</div>
<div class="class" attribute="otherfriend">
<span class="child">Test2</span>
</div>
<div class="class" attribute="otherfriend">
<span class="child">Test3</span>
</div>
我希望每个第一个 <div> 都具有要选择的任何值的属性,而不偏向于该值,例如第一个<div>,属性值为mrmcpowned,第一个<div>,属性值为friend,第一个<div>,属性值为otherfriend。
【问题讨论】:
-
我相信目前用 CSS3 是不可能的。
-
提取属性值是什么意思?对于
attr()函数,[attribute=attr(attribute)]应该是什么意思? -
在 CSS
content属性中,attr()用于显示选定 CSS 的选定属性的内容。例如,<a href="http://stackoverflow.com">Link</a>中的attr(href)将显示 stackoverflow.com。我要选择的内容连续重复属性,我只想要列表中具有重复属性值的第一个。 -
我的评论过早提交了,请回看。
标签: jquery css css-selectors