2

Hi I have a question about css. I want to change the color the first element of class 'active' which is "3".

This is my code, but it doesn't work.

.item.active:first-child {
  color: red
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="item clone" style="width:250px">1</div>
<div class="item clone" style="width:250px">2</div>
<div class="item active" style="width:250px">3</div>
<div class="item active" style="width:250px">4</div>
<div class="item active" style="width:250px">5</div>
<div class="item" style="width:250px">6</div>
<div class="item" style="width:250px">6</div>

And Is there any way to solve this problem with Jquery???

Please help.

4b0
  • 21,981
  • 30
  • 95
  • 142
user1833620
  • 751
  • 1
  • 10
  • 30

2 Answers2

3

You can use first with class like this in jquery.

$( ".active:first" ).css( "color", "red" );
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="item clone" style="width:250px">1</div>
<div class="item clone" style="width:250px">2</div>
<div class="item active" style="width:250px">3</div>
<div class="item active" style="width:250px">4</div>
<div class="item active" style="width:250px">5</div>
<div class="item" style="width:250px">6</div>
<div class="item" style="width:250px">6</div>
4b0
  • 21,981
  • 30
  • 95
  • 142
0
Using owl carousel center event You can also achieved the same:   

 .center {
            color: red;
        }

     $('.nonloop').owlCarousel({
                    center: true,
                    items: 2,
                    loop: false,
                    margin: 10,
                    responsive: {
                        600: {
                            items: 4
                        }
                    }
                });
Manish
  • 347
  • 1
  • 9