0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-04 16:24:22 +01:00
Bootstrap/docs/4.1/utilities/colors.md

62 lines
3.0 KiB
Markdown
Raw Normal View History

---
layout: docs
title: Colors
2017-05-28 20:25:59 +02:00
description: Convey meaning through color with a handful of color utility classes. Includes support for styling links with hover states, too.
group: utilities
2017-05-28 20:25:59 +02:00
toc: true
---
## Color
2018-03-14 16:44:38 +01:00
{% capture example %}
{% for color in site.data.theme-colors %}
2017-10-03 05:57:24 +02:00
<p class="text-{{ color.name }}{% if color.name == "light" %} bg-dark{% endif %}">.text-{{ color.name }}</p>{% endfor %}
2018-03-31 23:45:23 +02:00
<p class="text-body">.text-body</p>
<p class="text-muted">.text-muted</p>
2017-10-03 05:57:24 +02:00
<p class="text-white bg-dark">.text-white</p>
2018-03-31 23:45:23 +02:00
<p class="text-black-50">.text-black-50</p>
<p class="text-white-50 bg-dark">.text-white-50</p>
2018-03-14 16:44:38 +01:00
{% endcapture %}
{% include example.html content=example %}
2017-10-03 05:57:24 +02:00
Contextual text classes also work well on anchors with the provided hover and focus states. **Note that the `.text-white` and `.text-muted` class has no link styling.**
2018-03-14 16:44:38 +01:00
{% capture example %}
{% for color in site.data.theme-colors %}
2017-10-03 05:57:24 +02:00
<p><a href="#" class="text-{{ color.name }}{% if color.name == "light" %} bg-dark{% endif %}">{{ color.name | capitalize }} link</a></p>{% endfor %}
<p><a href="#" class="text-muted">Muted link</a></p>
2017-10-03 05:57:24 +02:00
<p><a href="#" class="text-white bg-dark">White link</a></p>
2018-03-14 16:44:38 +01:00
{% endcapture %}
{% include example.html content=example %}
## Background color
Similar to the contextual text color classes, easily set the background of an element to any contextual class. Anchor components will darken on hover, just like the text classes. Background utilities **do not set `color`**, so in some cases you'll want to use `.text-*` utilities.
2018-03-14 16:44:38 +01:00
{% capture example %}
{% for color in site.data.theme-colors %}
<div class="p-3 mb-2 bg-{{ color.name }} {% if color.name == "light" or color.name == "warning" %}text-dark{% else %}text-white{% endif %}">.bg-{{ color.name }}</div>{% endfor %}
2017-10-03 05:57:24 +02:00
<div class="p-3 mb-2 bg-white text-dark">.bg-white</div>
2018-03-29 06:08:09 +02:00
<div class="p-3 mb-2 bg-transparent text-dark">.bg-transparent</div>
2018-03-14 16:44:38 +01:00
{% endcapture %}
{% include example.html content=example %}
## Background gradient
2017-10-19 20:44:05 +02:00
When `$enable-gradients` is set to true, you'll be able to use `.bg-gradient-` utility classes. **By default, `$enable-gradients` is disabled and the example below is intentionally broken.** This is done for easier customization from the moment you start using Bootstrap. [Learn about our Sass options]({{ site.baseurl }}/docs/{{ site.docs_version }}/getting-started/theming/#sass-options) to enable these classes and more.
2018-03-14 16:44:38 +01:00
{% capture example %}
{% for color in site.data.theme-colors %}
<div class="p-3 mb-2 bg-gradient-{{ color.name }} {% if color.name == "light" or color.name == "warning" %}text-dark{% else %}text-white{% endif %}">.bg-gradient-{{ color.name }}</div>{% endfor %}
2018-03-14 16:44:38 +01:00
{% endcapture %}
{% include example.html content=example %}
{% capture callout %}
#### Dealing with specificity
Sometimes contextual classes cannot be applied due to the specificity of another selector. In some cases, a sufficient workaround is to wrap your element's content in a `<div>` with the class.
{% endcapture %}
{% include callout.html content=callout type="info" %}
{% include callout-warning-color-assistive-technologies.md %}