定位CSS类的第二个实例 [英] Target the 2nd instance of a CSS Class

查看:87
本文介绍了定位CSS类的第二个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我使用的解决方案,我只有有限的CSS类。我想知道是否有一种方法可以针对第二个类,当有两个同名的类时。

Due to the solution i am using, i only have limited CSS classes. I would like to know if there is a way i can target the 2nd class, when there are 2 classes of the same name.

我有2个media-link实例与DIV一起被称为item。我基本上需要向该类的第二个实例添加其他样式。但是,这就是困难所在。我无法在代码中添加任何其他代码或类!我知道,这不是理想的选择,而是取决于所使用的解决方案,而不是个人选择。

I have 2 instances of media-link contained withing a DIV called item. I need to basically add additional styles to the 2nd instance of the class. However this is where the difficulty comes in... I can not add any additional code, or classes to the code! I know, not ideal but its down to the solution being used, not personal choice.

示例代码:

 <a href="#" class="media-link" style="display: block">
    <img src="images/ph-a.png" alt="">
 </a>
 <a href="#" class="media-link">
    <img src="images/auth-2-100px.png" alt="">
    <p class="author">Author: John Smith</p>
 </a>

在此先感谢您提出任何建议或解决方案。

Thanks in advance for any suggestions, or solutions.

推荐答案

您好,现在已经习惯了

.media-link:nth-child(2) {
// here style 
}

.media-link:nth-of-type(2){
// here style
}

这篇关于定位CSS类的第二个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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