search
HomeWeb Front-endHTML TutorialExamples of Bootstrap's various progress bars

Examples of Bootstrap's various progress bars

Jul 18, 2017 pm 04:43 PM
bootstrapschedule

This chapter will explain the Bootstrap progress bar. In this tutorial, you'll see how to use Bootstrap to create a progress bar for loading, redirect, or action states.

Bootstrap progress bars use CSS3 transitions and animations to achieve this effect. Internet Explorer 9 and earlier and older versions of Firefox do not support this feature, and Opera 12 does not support animations.

Default progress bar

The steps to create a basic progress bar are as follows:

Add a

with class .progress.

Next, within the above

, add an empty
with class .progress-bar.

Add a style attribute with a width expressed in percentage, for example style="60%"; means the progress bar is at 60%.

Let us take a look at the following example:

Example

<div class="progress">
    <div class="progress-bar" role="progressbar" aria-valuenow="60" 
        aria-valuemin="0" aria-valuemax="100" style="width: 40%;">
        <span class="sr-only">40% 完成</span>
    </div></div>

Basic style

The Bootstrap framework provides a basic style for the progress bar , a 100% width background color, and then a highlight color to indicate completion progress. In fact, it is very easy to make such a progress bar. Generally, two containers are used. The outer container has a certain width and a background color is set. The child element sets a width. For example, the completion degree is 30% (that is, the width ratio of the parent container). ), and set a highlight background color for it

The Bootstrap framework is also implemented in this way. It provides two containers. The outer container uses the "progress" style, and the sub-container uses the "progress- bar" style. Among them, progress is used to set the container style of the progress bar, and progress-bar is used to limit the progress of the progress bar

.progress {
  height: 20px;
  margin-bottom: 20px;
  overflow: hidden;
  background-color: #f5f5f5;
  border-radius: 4px;
  -webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, .1);  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .1);
}.progress-bar {
  float: left;
  width: 0;
  height: 100%;
  font-size: 12px;
  line-height: 20px;
  color: #fff;
  text-align: center;
  background-color: #428bca;
  -webkit-box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .15);  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .15);
  -webkit-transition: width .6s ease;  transition: width .6s ease;
}
<div>   <div></div>
</div>

A better way to write accessibility is as follows

<div><div><span>40% Complete</span></div></div>

The role attribute tells the search engine that this div is used as a progress bar; the aria-valuenow="40" attribute tells the current progress bar of 40%; aria-valuemin="0 "The attribute tells the minimum value of the progress bar to be 0%; the aria-valuemax="100" attribute tells the maximum value of the progress bar to be 100%


Colored progress bar

The progress bar in the Bootstrap framework is the same as the warning message box. In order to give the user a better experience, different progress bar colors are configured according to different states. It is called a colored progress bar here, which mainly includes the following four types:

 ☑ progress-bar-info: Indicates the information progress bar, the color of the progress bar is blue

 ☑ progress-bar- success: Indicates a successful progress bar, the color of the progress bar is green

 ☑ Progress-bar-warning: Indicates a warning progress bar, the color of the progress bar is yellow

 ☑ Progress-bar-danger: Indicates an error Progress bar, the color of the progress bar is red

The specific use is very simple. You only need to add the corresponding class name to the basic progress. Compared with the basic progress bar, the color progress bar is the color of the progress bar. Certain changes

.progress-bar-success {
  background-color: #5cb85c;
}.progress-bar-info {
  background-color: #5bc0de;
}.progress-bar-warning {
  background-color: #f0ad4e;
}.progress-bar-danger {
  background-color: #d9534f;
}
<div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div>

Striped Progress Bar

In addition to providing a colored progress bar, the Bootstrap framework also provides a Striped progress bar, this striped progress bar is implemented using CSS3 linear gradient without using any pictures. To use the striped progress bar in the Bootstrap framework, you only need to add the class name "progress-striped" to the container "progress" of the progress bar. Of course, if you want the progress bar stripes to have a color effect like colored progress, you only need to add the class name "progress-striped" to the progress bar. Add the corresponding color class name to the bar

[Note] You can create a stripe effect for the progress bar through gradients. IE9-browser does not support

.progress-striped .progress-bar {
  background-image: -webkit-linear-gradient(45deg, rgba(255, 255, 255, .15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, .15) 50%, rgba(255, 255, 255, .15) 75%, transparent 75%, transparent);
  background-image:linear-gradient(45deg, rgba(255, 255, 255, .15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, .15) 50%, rgba(255, 255, 255, .15) 75%, transparent 75%, transparent);
  background-size: 40px 40px;
}
.progress-striped .progress-bar-success {
  background-image: -webkit-linear-gradient(45deg, rgba(255, 255, 255, .15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, .15) 50%, rgba(255, 255, 255, .15) 75%, transparent 75%, transparent);
  background-image:linear-gradient(45deg, rgba(255, 255, 255, .15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, .15) 50%, rgba(255, 255, 255, .15) 75%, transparent 75%, transparent);
}.progress-striped .progress-bar-info {
  background-image: -webkit-linear-gradient(45deg, rgba(255, 255, 255, .15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, .15) 50%, rgba(255, 255, 255, .15) 75%, transparent 75%, transparent);
  background-image:linear-gradient(45deg, rgba(255, 255, 255, .15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, .15) 50%, rgba(255, 255, 255, .15) 75%, transparent 75%, transparent);
}.progress-striped .progress-bar-warning {
  background-image: -webkit-linear-gradient(45deg, rgba(255, 255, 255, .15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, .15) 50%, rgba(255, 255, 255, .15) 75%, transparent 75%, transparent);
  background-image:linear-gradient(45deg, rgba(255, 255, 255, .15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, .15) 50%, rgba(255, 255, 255, .15) 75%, transparent 75%, transparent);
}.progress-striped .progress-bar-danger {
  background-image: -webkit-linear-gradient(45deg, rgba(255, 255, 255, .15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, .15) 50%, rgba(255, 255, 255, .15) 75%, transparent 75%, transparent);
  background-image:linear-gradient(45deg, rgba(255, 255, 255, .15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, .15) 50%, rgba(255, 255, 255, .15) 75%, transparent 75%, transparent);
}
<div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div>


Dynamic Stripes

In order to make the striped progress bar move, the Bootstrap framework also provides a dynamic stripe progress bar. Its implementation principle is mainly accomplished through animation of CSS3. First, a progress-bar-stripes animation is created through @keyframes. This animation mainly does one thing, which is to change the position of the background image, which is the value of background-position. Because the striped progress bar is made through the linear gradient of CSS3, and linear-gradient implements the background image in the corresponding background

[Note] IE9-browser does not support

@-webkit-keyframes progress-bar-stripes {
  from {
    background-position: 40px 0;
  }
  to {background-position: 0 0;
  }}
@keyframes progress-bar-stripes {
  from {
    background-position: 40px 0;
  }
  to {background-position: 0 0;
  }}

In the Bootstrap framework, add a class name "active" to the progress bar container "progress", and let the "progress-bar-stripes" animation take effect when the document is loaded, so that it appears from the right Animation effect of left movement

.progress.active .progress-bar {
  -webkit-animation: progress-bar-stripes 2s linear infinite;  animation: progress-bar-stripes 2s linear infinite;
}
<div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div>


##Cascading progress bar

In addition to the above-mentioned progress bars, the Bootstrap framework also provides a cascading progress bar. Cascading progress bars can place progress bars in different states together and arrange them horizontally

Put multiple progress bars into the same

.progress to make them appear stacked

<div>
  <div>
<span>35% Complete (success)</span>
  </div>
  <div>
<span>20% Complete (warning)</span>
  </div>
  <div>
<span>10% Complete (danger)</span>
  </div>
</div>


[Note] The sum of the cascading progress bars cannot be greater than 100%

<div>
  <div></div>
  <div></div>
  <div></div>
</div>


 

提示标签

  在实际开发中,有很多时候是需要在进度条中直接用相关的数值向用户传递完成的进度值,Bootstrap考虑了这种使用场景,只需要在进度条中添加需要的值

<div><div>20%</div></div>


  在展示很低的百分比时,如果需要让文本提示能够清晰可见,可以为进度条设置 min-width 属性 

<div><div>0%</div></div><div><div>0%</div></div><div><div>1%</div></div><div><div>1%</div></div>


 

The above is the detailed content of Examples of Bootstrap's various progress bars. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
HTML: The Structure, CSS: The Style, JavaScript: The BehaviorHTML: The Structure, CSS: The Style, JavaScript: The BehaviorApr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The Future of HTML: Evolution and Trends in Web DesignThe Future of HTML: Evolution and Trends in Web DesignApr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

HTML vs. CSS vs. JavaScript: A Comparative OverviewHTML vs. CSS vs. JavaScript: A Comparative OverviewApr 16, 2025 am 12:04 AM

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML: Is It a Programming Language or Something Else?HTML: Is It a Programming Language or Something Else?Apr 15, 2025 am 12:13 AM

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML: Building the Structure of Web PagesHTML: Building the Structure of Web PagesApr 14, 2025 am 12:14 AM

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

From Text to Websites: The Power of HTMLFrom Text to Websites: The Power of HTMLApr 13, 2025 am 12:07 AM

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

Understanding HTML, CSS, and JavaScript: A Beginner's GuideUnderstanding HTML, CSS, and JavaScript: A Beginner's GuideApr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

The Role of HTML: Structuring Web ContentThe Role of HTML: Structuring Web ContentApr 11, 2025 am 12:12 AM

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor