diff options
| author | Mark Otto <[email protected]> | 2016-12-29 14:56:28 -0800 |
|---|---|---|
| committer | Mark Otto <[email protected]> | 2016-12-30 22:46:00 -0800 |
| commit | a0141aa38e74108b4b5f805f8af65cb618236823 (patch) | |
| tree | 43ec28f47f740b3f7d766643a0748b7c011b2d0b /docs | |
| parent | 92fa9b2256a303fcf2034da0a11b9831490c4eb4 (diff) | |
| download | bootstrap-a0141aa38e74108b4b5f805f8af65cb618236823.tar.xz bootstrap-a0141aa38e74108b4b5f805f8af65cb618236823.zip | |
Rewrite progress component without <progress> element
- <progress> element didn't allow animation, labels overlaid, multiple bars, etc.
- Revamps CSS to use something more similar to v3's implementation
- Ditches variant mixin for `bg-` utils
- Rebuilds docs to match, including adding a new Height section for customizing that.
Only potential remaining todo is adding `.sr-only` instances to within the bar. Unsure if that's necessary.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/components/progress.md | 128 |
1 files changed, 98 insertions, 30 deletions
diff --git a/docs/components/progress.md b/docs/components/progress.md index d137fad14..29436c365 100644 --- a/docs/components/progress.md +++ b/docs/components/progress.md @@ -5,71 +5,139 @@ description: Documentation and examples for using Bootstrap progress bars. group: components --- -Stylize [the HTML5 `<progress>` element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/progress) with a few extra classes and some crafty browser-specific CSS. Be sure to read up on the browser support. +Use our custom progress component for displaying simple or complex progress bars. We don't use [the HTML5 `<progress>` element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/progress), ensuring you can stack progress bars, animate them, and place text labels over them. ## Contents * Will be replaced with the ToC, excluding the "Contents" header {:toc} -## Example +## How it works -To caption a progress bar, simply add a `<div>` with your caption text, [align the text using a utility class]({{ site.baseurl }}/utilities/typography/#text-alignment), and associate the caption with the `<progress>` element using the `aria-describedby` attribute. +Progress components are built with two HTML elements, some CSS to set the width, and a few attributes. + +- We use the `.progress` as a wrapper to indicate the max value of the progress bar. +- We use the inner `.progress-bar` to indicate the progress so far. +- The `.progress-bar` requires an inline style or custom CSS to set their width. +- The `.progress-bar` also requires some `role` and `aria` attributes to make it accessible. + +Put that all together, and you have the following examples. {% example html %} +<div class="progress"> + <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div> +</div> +<div class="progress"> + <div class="progress-bar" role="progressbar" style="width: 25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div> +</div> +<div class="progress"> + <div class="progress-bar" role="progressbar" style="width: 50%" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div> +</div> +<div class="progress"> + <div class="progress-bar" role="progressbar" style="width: 75%" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div> +</div> +<div class="progress"> + <div class="progress-bar" role="progressbar" style="width: 100%" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div> +</div> +{% endexample %} -<div class="text-center" id="example-caption-1">Reticulating splines… 0%</div> -<progress class="progress" value="0" max="100" aria-describedby="example-caption-1"></progress> +## Customizing -<div class="text-center" id="example-caption-2">Reticulating splines… 25%</div> -<progress class="progress" value="25" max="100" aria-describedby="example-caption-2"></progress> +Customize the appearance of your progress bars with custom CSS, background utilities, stripes, and more. -<div class="text-center" id="example-caption-3">Reticulating splines… 50%</div> -<progress class="progress" value="50" max="100" aria-describedby="example-caption-3"></progress> +### Labels -<div class="text-center" id="example-caption-4">Reticulating splines… 75%</div> -<progress class="progress" value="75" max="100" aria-describedby="example-caption-4"></progress> +Add labels to your progress bars by placing text within the `.progress-bar`. -<div class="text-center" id="example-caption-5">Reticulating splines… 100%</div> -<progress class="progress" value="100" max="100" aria-describedby="example-caption-5"></progress> +{% example html %} +<div class="progress"> + <div class="progress-bar" role="progressbar" style="width: 25%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">25%</div> +</div> {% endexample %} -## Contextual alternatives +### Height -Progress bars use some of the same button and alert classes for consistent styles. +We only set a `height` value on the `.progress-bar`, so if you change that value the outer `.progress` will automatically resize accordingly. {% example html %} -<progress class="progress progress-success" value="25" max="100"></progress> -<progress class="progress progress-info" value="50" max="100"></progress> -<progress class="progress progress-warning" value="75" max="100"></progress> -<progress class="progress progress-danger" value="100" max="100"></progress> +<div class="progress"> + <div class="progress-bar" role="progressbar" style="width: 25%; height: 1px;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div> +</div> +<div class="progress"> + <div class="progress-bar" role="progressbar" style="width: 25%; height: 20px;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div> +</div> +{% endexample %} + +### Backgrounds + +Use background utility classes to change the appearance of individual progress bars. + +{% example html %} +<div class="progress"> + <div class="progress-bar bg-success" role="progressbar" style="width: 25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div> +</div> +<div class="progress"> + <div class="progress-bar bg-info" role="progressbar" style="width: 50%" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div> +</div> +<div class="progress"> + <div class="progress-bar bg-warning" role="progressbar" style="width: 75%" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div> +</div> +<div class="progress"> + <div class="progress-bar bg-danger" role="progressbar" style="width: 100%" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div> +</div> +{% endexample %} + +### Multiple bars + +Include multiple progress bars in a progress component if you need. + +{% example html %} +<div class="progress"> + <div class="progress-bar" role="progressbar" style="width: 15%" aria-valuenow="15" aria-valuemin="0" aria-valuemax="100"></div> + <div class="progress-bar bg-success" role="progressbar" style="width: 30%" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100"></div> + <div class="progress-bar bg-info" role="progressbar" style="width: 20%" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100"></div> +</div> {% endexample %} ### Striped -Uses a gradient to create a striped effect. +Add `.progress-bar-striped` to any `.progress-bar` to apply a stripe via CSS gradient over the progress bar's background color. {% example html %} -<progress class="progress progress-striped" value="10" max="100"></progress> -<progress class="progress progress-striped progress-success" value="25" max="100"></progress> -<progress class="progress progress-striped progress-info" value="50" max="100"></progress> -<progress class="progress progress-striped progress-warning" value="75" max="100"></progress> -<progress class="progress progress-striped progress-danger" value="100" max="100"></progress> +<div class="progress"> + <div class="progress-bar progress-bar-striped" role="progressbar" style="width: 10%" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100"></div> +</div> +<div class="progress"> + <div class="progress-bar progress-bar-striped bg-success" role="progressbar" style="width: 25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div> +</div> +<div class="progress"> + <div class="progress-bar progress-bar-striped bg-info" role="progressbar" style="width: 50%" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div> +</div> +<div class="progress"> + <div class="progress-bar progress-bar-striped bg-warning" role="progressbar"style="width: 75%" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" ></div> +</div> +<div class="progress"> + <div class="progress-bar progress-bar-striped bg-danger" role="progressbar" style="width: 100%" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div> +</div> {% endexample %} ### Animated stripes -The striped gradient can also be animated. Add `.progress-animated` to `.progress` to animate the stripes right to left via CSS3 animations. +The striped gradient can also be animated. Add `.progress-bar-animated` to `.progress-bar` to animate the stripes right to left via CSS3 animations. -**Animated progress bars don't work in Opera 12**—as they don't support CSS3 animations. They also **don't work in IE10+ and Microsoft Edge** as those browsers currently don't support CSS3 animations on the [`::-ms-fill` pseudo-element](https://msdn.microsoft.com/en-us/library/windows/apps/hh465757.aspx). +**Animated progress bars don't work in Opera 12**—as they don't support CSS3 animations. <div class="bd-example"> - <progress class="progress progress-striped" value="25" max="100"></progress> - <button type="button" class="btn btn-secondary bd-activate-animated-progressbar" data-toggle="button" aria-pressed="false" autocomplete="off"> + <div class="progress"> + <div class="progress-bar progress-bar-striped" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" style="width: 75%"></div> + </div> + <button type="button" class="btn btn-secondary bd-toggle-animated-progress" data-toggle="button" aria-pressed="false" autocomplete="off"> Toggle animation </button> </div> {% highlight html %} -<progress class="progress progress-striped progress-animated" value="25" max="100"></progress> +<div class="progress"> + <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" style="width: 75%"></div> +</div> {% endhighlight %} |
