更改具有相同 ID joomla 的模块标题之一的 ID

Changing id of one of the module titles having same id joomla

我有这三个模块都具有相同的 id:

<?php if ($this->countModules('user2')) : ?>
    <div id="user2-wrap"><div id="user2" class="container row clr">
        <jdoc:include type="modules" name="user2" style="usergrid" grid="<?php echo $user2_width; ?>" />
    </div></div>
<?php endif; ?>

检查后我得到:

    <div id="user2-wrap"><div id="user2" class="container row clr">
                    <div class="module   span_4 col clr">
                <h3 class="module-title">Our Story</h3>
            <div class="module-body"> 
    <div class="custom">

<div id="user2-wrap"><div id="user2" class="container row clr">
                    <div class="module   span_4 col clr">
                <h3 class="module-title">Featured Training</h3>
            <div class="module-body"> 
    <div class="custom">


<div id="user2-wrap"><div id="user2" class="container row clr">
                    <div class="module   span_4 col clr">
                <h3 class="module-title">Chapters</h3>
            <div class="module-body"> 
    <div class="custom">

所有这些都相同 class module-title 我需要更改一个 module-title 的颜色。我如何更改一个特定 module-title 的 ID?或者还有其他方法吗?

尝试将 nth-child 解决方案与您的 module-title class 一起使用。

:nth-child(number_of_the_child_you_want_to_change) {
   your css declarations;
}

这里是linkCSS nth-child

编辑:如果您 want/can 使用 JavaScript,请使用此代码 select 文档中带有 class="module-title" 的第二个元素。

<script>
document.querySelectorAll('.module-title')[1].style.color = "red";
</script>

我更改了文本颜色,您需要将自己的更改插入到 class 元素中。