Tabs with different colors using css and jquery

0

I need to make some tabs to display information according to the tab clicked, what I do not know how to do is the colors of the tabs, they are different colors when you click each , like could I do this with css and jquery?

    
asked by anonymous 28.11.2017 / 19:35

1 answer

1

You can create different styles for each flap, each one with its color.

In the example below I did this and added tabindex to can use in CSS :focus , and I put a jQuery listener to identify which tab was clicked from its tabindex :

  

The snippet interpreter has a bug . It starts indexing from :nth-child to 0 ,   when in fact it would be in 1 .

$('.abas').on('click', function(){
   alert('Aba '+ $(this).attr('tabindex') +' clicada!');
});
.abas{
   display: block;
   width: 50px;
   height: 40px;
   line-height: 40px;
   text-align: center;
   border-bottom: 3px solid #ddd;
   float: left;
   cursor: pointer;
   outline: none;
}

.abas:hover,
.abas:focus{
   color: #fff;
}

.abas:nth-child(1){
   border-bottom-color: orange;
}
   .abas:nth-child(1):hover,
   .abas:nth-child(1):focus{
      background: orange;
   }

.abas:nth-child(2){
   border-bottom-color: red;
}
   .abas:nth-child(2):hover,
   .abas:nth-child(2):focus{
      background: red;
   }

.abas:nth-child(3){
   border-bottom-color: purple;
}
   .abas:nth-child(3):hover,
   .abas:nth-child(3):focus{
      background: purple;
   }

.abas:nth-child(4){
   border-bottom-color: blue;
}
   .abas:nth-child(4):hover,
   .abas:nth-child(4):focus{
      background: blue;
   }

.abas:nth-child(5){
   border-bottom-color: green;
}
   .abas:nth-child(5):hover,
   .abas:nth-child(5):focus{
      background: green;
   }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divclass="abas" tabindex="1">
   Aba 1
</div>
<div class="abas" tabindex="2">
   Aba 2
</div>
<div class="abas" tabindex="3">
   Aba 3
</div>
<div class="abas" tabindex="4">
   Aba 4
</div>
<div class="abas" tabindex="5">
   Aba 5
</div>
    
28.11.2017 / 20:07