Тема
Объедините одну из трех утилит темы с нашими классами цветов темы, чтобы задать пары color и background-color для любого элемента, как варианты компонентов.
| Класс | Стили |
|---|---|
| .theme-contrast | --bs-theme-fg: var(--bs-theme-contrast); --bs-theme-fg-emphasis: var(--bs-theme-contrast); |
| .theme-subtle | background-color: var(--bs-theme-bg-subtle); color: var(--bs-theme-fg); |
| .theme-muted | --bs-theme-fg: var(--bs-theme-fg-emphasis); |
| .theme-border | border: var(--bs-border-width) solid var(--bs-theme-border); |
Обзор
Возьмите любой из наших классов цвета темы и добавьте .theme-contrast, .theme-subtle или .theme-muted, чтобы задать предопределенную пару color и background-color. Затем при желании добавьте .theme-border`, чтобы задать предопределенный цвет границы. Подробнее о том, как работают цвета темы, см. документацию по теме в разделе «Настройка».
Контраст
.theme-contrast сочетает токен темы bg с цветом текста contrast для максимальной читаемости. Это идеально для элементов с высоким акцентом и сплошным фоном.
<div class="p-2 theme-primary theme-contrast">.theme-primary .theme-contrast</div>
<div class="p-2 theme-accent theme-contrast">.theme-accent .theme-contrast</div>
<div class="p-2 theme-success theme-contrast">.theme-success .theme-contrast</div>
<div class="p-2 theme-danger theme-contrast">.theme-danger .theme-contrast</div>
<div class="p-2 theme-warning theme-contrast">.theme-warning .theme-contrast</div>
<div class="p-2 theme-info theme-contrast">.theme-info .theme-contrast</div>
<div class="p-2 theme-inverse theme-contrast">.theme-inverse .theme-contrast</div>
<div class="p-2 theme-secondary theme-contrast">.theme-secondary .theme-contrast</div>Вложенные ссылки наследуют контрастный цвет текста, чтобы оставаться читаемыми на сплошном фоне:
<div class="p-3 theme-primary theme-contrast">Theme Primary with a <a class="underline-opacity-50 hover:underline-opacity-100" href="#">nested link</a> inside.</div>
<div class="p-3 theme-accent theme-contrast">Theme Accent with a <a class="underline-opacity-50 hover:underline-opacity-100" href="#">nested link</a> inside.</div>
<div class="p-3 theme-success theme-contrast">Theme Success with a <a class="underline-opacity-50 hover:underline-opacity-100" href="#">nested link</a> inside.</div>
<div class="p-3 theme-danger theme-contrast">Theme Danger with a <a class="underline-opacity-50 hover:underline-opacity-100" href="#">nested link</a> inside.</div>
<div class="p-3 theme-warning theme-contrast">Theme Warning with a <a class="underline-opacity-50 hover:underline-opacity-100" href="#">nested link</a> inside.</div>
<div class="p-3 theme-info theme-contrast">Theme Info with a <a class="underline-opacity-50 hover:underline-opacity-100" href="#">nested link</a> inside.</div>
<div class="p-3 theme-inverse theme-contrast">Theme Inverse with a <a class="underline-opacity-50 hover:underline-opacity-100" href="#">nested link</a> inside.</div>
<div class="p-3 theme-secondary theme-contrast">Theme Secondary with a <a class="underline-opacity-50 hover:underline-opacity-100" href="#">nested link</a> inside.</div>Приглушенный фон (subtle)
Subtle сочетает токен темы bg-subtle с цветом текста text для менее контрастного, более тонкого вида. Эта комбинация автоматически подстраивается под текущий цветовой режим.
<div class="p-2 theme-primary theme-subtle">.theme-primary .theme-subtle</div>
<div class="p-2 theme-accent theme-subtle">.theme-accent .theme-subtle</div>
<div class="p-2 theme-success theme-subtle">.theme-success .theme-subtle</div>
<div class="p-2 theme-danger theme-subtle">.theme-danger .theme-subtle</div>
<div class="p-2 theme-warning theme-subtle">.theme-warning .theme-subtle</div>
<div class="p-2 theme-info theme-subtle">.theme-info .theme-subtle</div>
<div class="p-2 theme-inverse theme-subtle">.theme-inverse .theme-subtle</div>
<div class="p-2 theme-secondary theme-subtle">.theme-secondary .theme-subtle</div>И с границами:
<div class="p-2 theme-primary theme-subtle theme-border">.theme-primary .theme-subtle .theme-border</div>
<div class="p-2 theme-accent theme-subtle theme-border">.theme-accent .theme-subtle .theme-border</div>
<div class="p-2 theme-success theme-subtle theme-border">.theme-success .theme-subtle .theme-border</div>
<div class="p-2 theme-danger theme-subtle theme-border">.theme-danger .theme-subtle .theme-border</div>
<div class="p-2 theme-warning theme-subtle theme-border">.theme-warning .theme-subtle .theme-border</div>
<div class="p-2 theme-info theme-subtle theme-border">.theme-info .theme-subtle .theme-border</div>
<div class="p-2 theme-inverse theme-subtle theme-border">.theme-inverse .theme-subtle .theme-border</div>
<div class="p-2 theme-secondary theme-subtle theme-border">.theme-secondary .theme-subtle .theme-border</div>Вложенные ссылки наследуют цвет текста subtle, чтобы оставаться читаемыми на фоне subtle:
<div class="p-3 theme-primary theme-subtle">Theme Primary with a <a class="underline-opacity-50 hover:underline-opacity-100" href="#">nested link</a> inside.</div>
<div class="p-3 theme-accent theme-subtle">Theme Accent with a <a class="underline-opacity-50 hover:underline-opacity-100" href="#">nested link</a> inside.</div>
<div class="p-3 theme-success theme-subtle">Theme Success with a <a class="underline-opacity-50 hover:underline-opacity-100" href="#">nested link</a> inside.</div>
<div class="p-3 theme-danger theme-subtle">Theme Danger with a <a class="underline-opacity-50 hover:underline-opacity-100" href="#">nested link</a> inside.</div>
<div class="p-3 theme-warning theme-subtle">Theme Warning with a <a class="underline-opacity-50 hover:underline-opacity-100" href="#">nested link</a> inside.</div>
<div class="p-3 theme-info theme-subtle">Theme Info with a <a class="underline-opacity-50 hover:underline-opacity-100" href="#">nested link</a> inside.</div>
<div class="p-3 theme-inverse theme-subtle">Theme Inverse with a <a class="underline-opacity-50 hover:underline-opacity-100" href="#">nested link</a> inside.</div>
<div class="p-3 theme-secondary theme-subtle">Theme Secondary with a <a class="underline-opacity-50 hover:underline-opacity-100" href="#">nested link</a> inside.</div>Выцветший (muted)
Muted сочетает токен темы bg-muted с цветом текста text-emphasis для менее контрастного, более приглушенного вида. Как и subtle, эта комбинация автоматически подстраивается под текущий цветовой режим.
<div class="p-2 theme-primary theme-muted">.theme-primary .theme-muted</div>
<div class="p-2 theme-accent theme-muted">.theme-accent .theme-muted</div>
<div class="p-2 theme-success theme-muted">.theme-success .theme-muted</div>
<div class="p-2 theme-danger theme-muted">.theme-danger .theme-muted</div>
<div class="p-2 theme-warning theme-muted">.theme-warning .theme-muted</div>
<div class="p-2 theme-info theme-muted">.theme-info .theme-muted</div>
<div class="p-2 theme-inverse theme-muted">.theme-inverse .theme-muted</div>
<div class="p-2 theme-secondary theme-muted">.theme-secondary .theme-muted</div>И с границами:
<div class="p-2 theme-primary theme-muted theme-border">.theme-primary .theme-muted .theme-border</div>
<div class="p-2 theme-accent theme-muted theme-border">.theme-accent .theme-muted .theme-border</div>
<div class="p-2 theme-success theme-muted theme-border">.theme-success .theme-muted .theme-border</div>
<div class="p-2 theme-danger theme-muted theme-border">.theme-danger .theme-muted .theme-border</div>
<div class="p-2 theme-warning theme-muted theme-border">.theme-warning .theme-muted .theme-border</div>
<div class="p-2 theme-info theme-muted theme-border">.theme-info .theme-muted .theme-border</div>
<div class="p-2 theme-inverse theme-muted theme-border">.theme-inverse .theme-muted .theme-border</div>
<div class="p-2 theme-secondary theme-muted theme-border">.theme-secondary .theme-muted .theme-border</div>Вложенные ссылки наследуют цвет текста muted, чтобы оставаться читаемыми на фоне muted:
<div class="p-3 theme-primary theme-muted">Theme Primary with a <a class="underline-opacity-50 hover:underline-opacity-100" href="#">nested link</a> inside.</div>
<div class="p-3 theme-accent theme-muted">Theme Accent with a <a class="underline-opacity-50 hover:underline-opacity-100" href="#">nested link</a> inside.</div>
<div class="p-3 theme-success theme-muted">Theme Success with a <a class="underline-opacity-50 hover:underline-opacity-100" href="#">nested link</a> inside.</div>
<div class="p-3 theme-danger theme-muted">Theme Danger with a <a class="underline-opacity-50 hover:underline-opacity-100" href="#">nested link</a> inside.</div>
<div class="p-3 theme-warning theme-muted">Theme Warning with a <a class="underline-opacity-50 hover:underline-opacity-100" href="#">nested link</a> inside.</div>
<div class="p-3 theme-info theme-muted">Theme Info with a <a class="underline-opacity-50 hover:underline-opacity-100" href="#">nested link</a> inside.</div>
<div class="p-3 theme-inverse theme-muted">Theme Inverse with a <a class="underline-opacity-50 hover:underline-opacity-100" href="#">nested link</a> inside.</div>
<div class="p-3 theme-secondary theme-muted">Theme Secondary with a <a class="underline-opacity-50 hover:underline-opacity-100" href="#">nested link</a> inside.</div>Сравнение
Ниже приведено сравнение всех трех стилей бок о бок для каждого цвета темы, включая вложенные ссылки:
<div class="d-flex gap-2 mb-2">
<div class="theme-primary theme-contrast p-3 flex-fill text-center rounded">Primary со <a class="underline-opacity-50 hover:underline-opacity-100" href="#">ссылкой</a></div>
<div class="theme-primary theme-subtle p-3 flex-fill text-center rounded">Primary со <a class="underline-opacity-50 hover:underline-opacity-100" href="#">ссылкой</a></div>
<div class="theme-primary theme-muted p-3 flex-fill text-center rounded">Primary со <a class="underline-opacity-50 hover:underline-opacity-100" href="#">ссылкой</a></div>
</div>
<div class="d-flex gap-2 mb-2">
<div class="theme-accent theme-contrast p-3 flex-fill text-center rounded">Accent со <a class="underline-opacity-50 hover:underline-opacity-100" href="#">ссылкой</a></div>
<div class="theme-accent theme-subtle p-3 flex-fill text-center rounded">Accent со <a class="underline-opacity-50 hover:underline-opacity-100" href="#">ссылкой</a></div>
<div class="theme-accent theme-muted p-3 flex-fill text-center rounded">Accent со <a class="underline-opacity-50 hover:underline-opacity-100" href="#">ссылкой</a></div>
</div>
<div class="d-flex gap-2 mb-2">
<div class="theme-success theme-contrast p-3 flex-fill text-center rounded">Success со <a class="underline-opacity-50 hover:underline-opacity-100" href="#">ссылкой</a></div>
<div class="theme-success theme-subtle p-3 flex-fill text-center rounded">Success со <a class="underline-opacity-50 hover:underline-opacity-100" href="#">ссылкой</a></div>
<div class="theme-success theme-muted p-3 flex-fill text-center rounded">Success со <a class="underline-opacity-50 hover:underline-opacity-100" href="#">ссылкой</a></div>
</div>
<div class="d-flex gap-2 mb-2">
<div class="theme-danger theme-contrast p-3 flex-fill text-center rounded">Danger со <a class="underline-opacity-50 hover:underline-opacity-100" href="#">ссылкой</a></div>
<div class="theme-danger theme-subtle p-3 flex-fill text-center rounded">Danger со <a class="underline-opacity-50 hover:underline-opacity-100" href="#">ссылкой</a></div>
<div class="theme-danger theme-muted p-3 flex-fill text-center rounded">Danger со <a class="underline-opacity-50 hover:underline-opacity-100" href="#">ссылкой</a></div>
</div>
<div class="d-flex gap-2 mb-2">
<div class="theme-warning theme-contrast p-3 flex-fill text-center rounded">Warning со <a class="underline-opacity-50 hover:underline-opacity-100" href="#">ссылкой</a></div>
<div class="theme-warning theme-subtle p-3 flex-fill text-center rounded">Warning со <a class="underline-opacity-50 hover:underline-opacity-100" href="#">ссылкой</a></div>
<div class="theme-warning theme-muted p-3 flex-fill text-center rounded">Warning со <a class="underline-opacity-50 hover:underline-opacity-100" href="#">ссылкой</a></div>
</div>
<div class="d-flex gap-2 mb-2">
<div class="theme-info theme-contrast p-3 flex-fill text-center rounded">Info со <a class="underline-opacity-50 hover:underline-opacity-100" href="#">ссылкой</a></div>
<div class="theme-info theme-subtle p-3 flex-fill text-center rounded">Info со <a class="underline-opacity-50 hover:underline-opacity-100" href="#">ссылкой</a></div>
<div class="theme-info theme-muted p-3 flex-fill text-center rounded">Info со <a class="underline-opacity-50 hover:underline-opacity-100" href="#">ссылкой</a></div>
</div>
<div class="d-flex gap-2 mb-2">
<div class="theme-inverse theme-contrast p-3 flex-fill text-center rounded">Inverse со <a class="underline-opacity-50 hover:underline-opacity-100" href="#">ссылкой</a></div>
<div class="theme-inverse theme-subtle p-3 flex-fill text-center rounded">Inverse со <a class="underline-opacity-50 hover:underline-opacity-100" href="#">ссылкой</a></div>
<div class="theme-inverse theme-muted p-3 flex-fill text-center rounded">Inverse со <a class="underline-opacity-50 hover:underline-opacity-100" href="#">ссылкой</a></div>
</div>
<div class="d-flex gap-2 mb-2">
<div class="theme-secondary theme-contrast p-3 flex-fill text-center rounded">Secondary со <a class="underline-opacity-50 hover:underline-opacity-100" href="#">ссылкой</a></div>
<div class="theme-secondary theme-subtle p-3 flex-fill text-center rounded">Secondary со <a class="underline-opacity-50 hover:underline-opacity-100" href="#">ссылкой</a></div>
<div class="theme-secondary theme-muted p-3 flex-fill text-center rounded">Secondary со <a class="underline-opacity-50 hover:underline-opacity-100" href="#">ссылкой</a></div>
</div>С компонентами
Утилиты темы отлично работают с компонентами, поддерживающими темизацию. Примените цвет темы к контейнеру и используйте классы стиля темы на отдельных элементах.
<div class="theme-primary">
<div class="d-flex gap-2 mb-3">
<span class="badge theme-contrast">Контрастный значок</span>
<span class="badge theme-subtle">Значок subtle</span>
<span class="badge theme-muted">Значок muted</span>
</div>
</div>
<div class="theme-danger">
<div class="d-flex gap-2 mb-3">
<span class="badge theme-contrast">Контрастный значок</span>
<span class="badge theme-subtle">Значок subtle</span>
<span class="badge theme-muted">Значок muted</span>
</div>
</div>Можно также смешивать цвета темы в одном контейнере, применяя разные классы .theme-{color} к дочерним элементам:
<div class="d-flex gap-2">
<div class="theme-success theme-contrast p-3 rounded">Успех</div>
<div class="theme-warning theme-contrast p-3 rounded">Предупреждение</div>
<div class="theme-danger theme-contrast p-3 rounded">Опасность</div>
</div>Сброс
Используйте .theme-reset, когда вложенное поддерево должно отказаться от унаследованной темы и вернуться к значениям компонентов по умолчанию. Подробнее см. Классы утилит темы.
<div class="theme-primary p-3 rounded">
<span class="badge theme-contrast">Основной значок</span>
<span class="badge theme-reset">Значок по умолчанию</span>
</div>CSS
Сгенерированный CSS
Классы стиля темы генерируют следующий CSS:
.theme-contrast {
--theme-fg: var(--theme-contrast);
--theme-fg-emphasis: var(--theme-contrast);
background-color: var(--theme-bg);
color: var(--theme-contrast);
}
.theme-subtle {
background-color: var(--theme-bg-subtle);
color: var(--theme-fg);
}
.theme-muted {
--theme-fg: var(--theme-fg-emphasis);
background-color: var(--theme-bg-muted);
color: var(--theme-fg-emphasis);
}
API утилит Sass
Утилиты темы объявлены в нашем API утилит в scss/_utilities.scss. Узнайте, как использовать API утилит.
// Theme style utilities - pair with .theme-{color} to apply coordinated bg + text colors
"theme-contrast": (
property: (
"background-color": var(--theme-bg),
"color": var(--theme-contrast)
),
class: theme-contrast,
values: (null: null)
),
"theme-subtle": (
property: (
"background-color": var(--theme-bg-subtle),
"color": var(--theme-fg)
),
class: theme-subtle,
values: (null: null)
),
"theme-muted": (
property: (
"background-color": var(--theme-bg-muted),
"color": var(--theme-fg-emphasis)
),
class: theme-muted,
values: (null: null)
),
"theme-border": (
property: border,
class: theme-border,
values: (null: var(--border-width) solid var(--theme-border))
),