首页 > 解决方案 > 选择第二个匹配的类项,而不是 CSS 中的元素

问题描述

这仅在 CSS 中可行吗?我无权访问 HTML 或 JS。我需要选择第二个匹配选择器,而不是元素。

这在页面中重复了两次,但我找不到只更改第二个元素的样式的方法。

.testimonials .testimonials-content .cover-component-slide{
    /* Change the second one */
}

标签: htmlcss

解决方案


.msg:nth-of-type(2) {
    color: red;
}
<h1 class="msg">Hello World One</h1>
<h1 class="msg">Hello World Two</h1>


推荐阅读