Подтвердить что ты не робот

Настроить вкладку "Угловой материал"

Я использую angular 4, и я использую angular материал.

<md-tab-group [disableRipple]=true>
    <md-tab label="Tab 1"></md-tab>
    <md-tab label="Tab 2"></md-tab>
</md-tab-group>

Как полностью настроить цвет фона, когда (не выбран/не выбран), цвет текста и т.д. Я уже пробовал использовать псевдо-классы... но все еще безрезультатно. --- Я успешно установил font-size, но при настройке цвет текста немного нервный. Пожалуйста, помогите.

Обновление:

Я пытался изменить фон на прозрачный при выборе... пытался переопределить цвет, когда ссылка не выбрана на вкладке и т.д., Но по-прежнему не работает.

/* Styles go here */

  .mat-tab-label{
    color:white;
    min-width: 25px !important;
    padding: 5px;
       background-color:transparent;
        color:white;
        font-weight: 700;
  }

  /deep/ .mat-tab-label{
    min-width: 25px !important;
    padding: 5px;
       background-color:transparent;
        color:white;
        font-weight: 700;
}

.md-tab.ng-scope.ng-isolate-scope.md-ink-ripple.md-active{
      background-color:transparent;
      color:white;
      font-weight: 700;
  }

.md-tab.ng-scope.ng-isolate-scope.md-ink-ripple{
    background-color:transparent;
    color:white;
    font-weight: 700;
}



.mat-tab-label:active{
    min-width: 25px !important;
    padding: 5px;
       background-color:transparent;
        color:white;
        font-weight: 700;
}

.mat-tab-label:selected{
    min-width: 25px !important;
    padding: 5px;
       background-color:transparent;
        color:white;
        font-weight: 700;
}
4b9b3361

Ответ 1

В своем компоненте установите параметр ViewEncapsulation в None и добавьте стили в файл component.css.

Изменения в машинописном коде:

import {Component, ViewEncapsulation} from '@angular/core';

@Component({
  ....
  encapsulation: ViewEncapsulation.None
})

Компонент CSS:

/* Styles for tab labels */
.mat-tab-label {
    min-width: 25px !important;
    padding: 5px;
    background-color: transparent;
    color: red;
    font-weight: 700;
}

/* Styles for the active tab label */
.mat-tab-label.mat-tab-label-active {
    min-width: 25px !important;
    padding: 5px;
    background-color: transparent;
    color: red;
    font-weight: 700;
}

/* Styles for the ink bar */
.mat-ink-bar {
    background-color: green;
}

демонстрация

Ответ 2

Обновление

Чтобы настроить фон вкладки и чернильную полосу, вы можете определить собственную тему, а затем использовать параметры темы в группе вкладок:

<div class="my-theme">
    <mat-tab-group [backgroundColor]="'primary'" [color]="'warn'">
        <mat-tab label="First"> Content 1 </mat-tab>
        <mat-tab label="Second"> Content 2 </mat-tab>
        <mat-tab label="Third"> Content 3 </mat-tab>
    </mat-tab-group>
</div>

Вот пример StackBlitz.

Старый ответ с :: ng-deep

Если вы не хотите прикасаться к ViewEncapsulation, используйте вместо этого :: ng-deep с селектором классов (проверьте с помощью инструмента разработки браузера).

Например (Angular 5, Материал 2):

/* active tab */
::ng-deep .mat-tab-list .mat-tab-labels .mat-tab-label-active {
color:red;
background-color: green;
}

/* ink bar */
::ng-deep .mat-ink-bar {
background-color: var(--primary-color,#1F89CE) !important;
}

Ответ 3

Мне потребовалось много времени, чтобы понять, как изменить цвет фона вкладок, переопределив дизайн материала. Я не знаю, где поделиться своим конечным результатом, так что здесь идет:

Для файла.ts:

@Component({
  selector: 'app-tabs',
  templateUrl: './tabs.component.html',
  styleUrls: ['./tabs.component.css'],
  encapsulation: ViewEncapsulation.None
})

Для файла CSS:

.mat-tab-labels, .mat-tab-label, .mat-tab-link {
  color: white;
  font-size: 16px;
  background-color: #804A71;
}

.mat-tab-group.mat-primary .mat-ink-bar, .mat-tab-nav-bar.mat-primary .mat-ink-bar{
  background: white;
  height: 5px; 
}

Так что это и цвет фона, и цвет, и размер текста (метки), и панель вкладок под текстом. Наконец-то это сработало, когда я использовал.mat-tab-label и.mat-tab-label.

Ответ 4

Последнее решение: -

1) Переопределить в styles.css 2) Используйте селектор компонента, в котором существует эта вкладка материала

styles.css

  app-child .mat-tab-label.mat-tab-label-active {
    padding: 0px 15px ;
  justify-content: flex-start;
  }

  app-child .mat-tab-label{
    padding: 0px 15px ;
  justify-content: flex-start;
  }

.mat-tab-group.mat-primary .mat-ink-bar, .mat-tab-nav-bar.mat-primary .mat-ink-bar{
    background:#6168e7;
  }

Ответ 5

Угловая версия 6

Новый дизайн для пользовательской вкладки

HTML

<mat-tab-group [disableRipple]="true" mat-align-tabs="center">
     <md-tab label="Tab 1"></md-tab>
     <md-tab label="Tab 2"></md-tab>
</md-tab-group>

scss

СКС
/deep/ .mat-tab-labels {
  min-width: auto !important;
  div {
    border: 1px solid #fff;
    background-color: #404040;
      &.mat-tab-label-active {
        background-color: #3aafa9;
        .mat-tab-label-content {
          border: none;
          background-color: #3aafa9;
          }
      }
      .mat-tab-label-content {
        border: none;
        color: #fff !important;
        }
    }
 }

 /deep/ .mat-tab-group{
  &.mat-primary {
    .mat-ink-bar {
      background-color: transparent;
    }
  }
 }

 /deep/ .mat-tab-body-wrapper{
   min-height: 550px
 }

 /deep/ .mat-tab-label-container {
   flex-grow: 0 !important;
 }

/deep/ .mat-tab-label{
  opacity: 1 !important;
 }