How to use custom color for tabs background in ionic?

14,538

You could define your own CSS classes for tab and bar Ionic tags. For example here is a snippet using tab-custom and bar-custom CSS styles:

angular.module('ionicApp', ['ionic'])

.config(function($stateProvider, $urlRouterProvider) {

  $stateProvider
    .state('tabs', {
      url: "/tab",
      abstract: true,
      templateUrl: "templates/tabs.html"
    })
    .state('tabs.home', {
      url: "/home",
      views: {
        'home-tab': {
          templateUrl: "templates/home.html",
          controller: 'HomeTabCtrl'
        }
      }
    })
    .state('tabs.about', {
      url: "/about",
      views: {
        'about-tab': {
          templateUrl: "templates/about.html"
        }
      }
    })
    .state('tabs.contact', {
      url: "/contact",
      views: {
        'contact-tab': {
          templateUrl: "templates/contact.html"
        }
      }
    });


   $urlRouterProvider.otherwise("/tab/home");

})

.controller('HomeTabCtrl', function($scope) {
  console.log('HomeTabCtrl');
});
.bar.bar-custom {
    border-color: #5D3A23;
    background-color: #5D3A23;
    background-image: linear-gradient(0deg, #0c60ee, #0c60ee 50%, transparent 50%);
    color: #fff; }
    .bar.bar-custom .title {
      color: #fff; }
    .bar.bar-custom.bar-footer {
      background-image: linear-gradient(180deg, #0c60ee, #0c60ee 50%, transparent 50%); }

.bar-custom .button {
  border-color: transparent;
  background-color: #5D3A23;
  color: #fff; }
  .bar-custom .button:hover {
    color: #fff;
    text-decoration: none; }
  .bar-custom .button.active, .bar-positive .button.activated {
    background-color: #0c60ee; }
  .bar-custom .button.button-clear {
    border-color: transparent;
    background: none;
    box-shadow: none;
    color: #fff;
    font-size: 17px; }
  .bar-custom .button.button-icon {
    border-color: transparent;
    background: none; }


.tabs-custom > .tabs,
.tabs.tabs-custom {
  border-color: #5D3A23;
  background-color: #5D3A23;
  background-image: linear-gradient(0deg, #0c60ee, #0c60ee 50%, transparent 50%);
  color: #fff; }
  .tabs-custom > .tabs .tab-item .badge,
  .tabs.tabs-custom .tab-item .badge {
    background-color: #fff;
    color: #387ef5; }

.tabs-striped.tabs-custom .tabs {
  background-color: #5D3A23; }

.tabs-striped.tabs-custom .tab-item {
  color: rgba(255, 255, 255, 0.4);
  opacity: 1; }
  .tabs-striped.tabs-custom .tab-item .badge {
    opacity: 0.4; }
  .tabs-striped.tabs-custom .tab-item.tab-item-active, .tabs-striped.tabs-custom .tab-item.active, .tabs-striped.tabs-positive .tab-item.activated {
    margin-top: -2px;
    color: #fff;
    border-style: solid;
    border-width: 2px 0 0 0;
    border-color: #fff; }
<html ng-app="ionicApp">

    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">

      <title>Tabs Example</title>

      <link href="//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet">
      <script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
    </head>

    <body>

      <ion-nav-bar class="bar-custom">
        <ion-nav-back-button>
        </ion-nav-back-button>
      </ion-nav-bar>

      <ion-nav-view></ion-nav-view>


      <script id="templates/tabs.html" type="text/ng-template">
        <ion-tabs class="tabs-icon-top tabs-custom">

          <ion-tab title="Home" icon="ion-home" href="#/tab/home">
            <ion-nav-view name="home-tab"></ion-nav-view>
          </ion-tab>

          <ion-tab title="About" icon="ion-ios-information" href="#/tab/about">
            <ion-nav-view name="about-tab"></ion-nav-view>
          </ion-tab>

          <ion-tab title="Contact" icon="ion-ios-world" ui-sref="tabs.contact">
            <ion-nav-view name="contact-tab"></ion-nav-view>
          </ion-tab>

        </ion-tabs>
      </script>

      <script id="templates/home.html" type="text/ng-template">
        <ion-view view-title="Home">
          <ion-content class="padding">
            <p>
              <a class="button icon icon-right ion-chevron-right" href="#/tab/facts">Scientific Facts</a>
            </p>
          </ion-content>
        </ion-view>
      </script>

      <script id="templates/about.html" type="text/ng-template">
        <ion-view view-title="About">
          <ion-content class="padding">
            <h3>Create hybrid mobile apps with the web technologies you love.</h3>
            <p>Free and open source, Ionic offers a library of mobile-optimized HTML, CSS and JS components for building highly interactive apps.</p>
            <p>Built with Sass and optimized for AngularJS.</p>
          </ion-content>
        </ion-view>
      </script>


      <script id="templates/contact.html" type="text/ng-template">
        <ion-view title="Contact">
          <ion-content>
            <div class="list">
              <div class="item">
                @IonicFramework
              </div>
              <div class="item">
                @DriftyTeam
              </div>
            </div>
          </ion-content>
        </ion-view>
      </script>

    </body>

    </html>
Share:
14,538
Amila Sampath
Author by

Amila Sampath

Enjoy with #nodejs#angularjs#mongodb#javascript#HTML5#Css#JavaScript#JWT#Ionic#Firebase#Jira#Git#Bitbucket#

Updated on June 28, 2022

Comments

  • Amila Sampath
    Amila Sampath almost 2 years

    I am developing ionic application

    Here my code

    <ion-tabs class="tabs-icon-top tabs-background-{......} tabs-color-active-positive" ng-controller="TabCtrl">
    
      <!-- Home Tab -->
      <ion-tab title="Menu"
               icon-on="ion-ios-book"
               ui-sref="tab.menu">
        <ion-nav-view name="tab-menu"></ion-nav-view>
      </ion-tab>
    

    When fill black using tabs-background-balanced Result

    enter image description here

    I need change tab background color as color of "The English Cake Company"

    I try using

    <ion-tabs class="tabs-icon-top tabs-background-{red} tabs-color-active-positive" ng-controller="TabCtrl">
    

    enter image description here

    If you not clear question, pls comment Thanks