Progress element html text inside - html

Hi there can someone help me with this progress html element I need to be able to put a text value on the right side of the progress and depending the progress if decreases the text to go with that
progress {
-webkit-appearance: none;
}
progress::-webkit-progress-bar {
background-color: orange;
}
<progress value="60" max="100"></progress><br/>
<progress value="90" max="100"></progress>
I need it like this on the photo

You should use a custom progress bar or a library that has an option for that. here is an example of a custom progress bar. Use Javascript to control the width and the content of the before pseudo-element
.progress{
height:30px;
width:300px;
background-color:orange;
position:relative;
}
.progress::before{
position:absolute;
height:30px;
background:green;
content:'50%';// hrere you should add the text
top:0;
left:0;
width:50%;
display:flex;
color:white;
align-items:center;
justify-content:flex-end;
padding-right:10px;
}
<div class="progress"></div>

I have updated the progress bar using pure css. Lets try with this example and comment for further information.
progress {
-webkit-appearance: none;
}
progress::-webkit-progress-bar {
background-color: orange;
}
.progress-bar span {
position: absolute;
display: inline-block;
color: #fff;
text-align: right;
}
.progress-bar {
display: block;
position: relative;
width: 100%;
}
progress {
width: 100%;
}
<div class="progress-bar">
<span data-value="60" style="width: 60%;">60</span>
<progress value="60" max="100"></progress>
</div>
<div class="progress-bar">
<span data-value="90" style="width: 90%;">90</span>
<progress value="90" max="100"></progress>
</div>

You have to use bootstrap latest version and it has in-built css :
Example :
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: 25%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">25%</div>
</div>
<br><br>
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: 15%" aria-valuenow="15" aria-valuemin="0" aria-valuemax="100">10%</div>
<div class="progress-bar bg-success" role="progressbar" style="width: 30%" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100">20%</div>
<div class="progress-bar bg-info" role="progressbar" style="width: 20%" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100">30%</div>
</div>

You can do it with little bit of js and css.
I would personally avoid the progress element cause of cross-browser styling issues.
Third party libraries are good but they come with a significant cost.
The bloated css and js are sometimes not worth it.
Hope this helps.
<style>
.progress {
width: 100%;
position: relative;
background-color: orange;
}
.bar {
width: 0%;
height: 30px;
background-color: green;
text-align: center;
line-height: 30px;
color: black;
}
.bar-text {
position: absolute;
top: 0;
width: 100%;
height: 30px;
text-align: center;
line-height: 30px;
color: black;
}
</style>
<script>
function init() {
var bar = document.getElementById("bar");
var width = 0;
var id = setInterval(frame, 10);
function frame() {
if (width >= 100) {
clearInterval(id);
} else {
width++;
bar.style.width = width + '%';
document.querySelector('.bar-text').innerHTML = width * 1 + '%';
}
}
}
</script>
<div class="progress" id="progress">
<div class="bar" id="bar"></div>
<div class="bar-text">10%</div>
</div>
<br>
<button onclick="init()">Click Me</button>

Related

CSS n'th class in another class

I just started to FE after a couple of years in BE.
Developing an analytics card with using Angular on FE and .net Core on BE.
Stucked on a point to find out the best practice about to change background-color: property of a class beneath of main class.
<div class="row">
<div class="journey-card-bottom">
<div *ngFor="let bottom of top.breakDown | keyvalue: originalOrder">
<div>
<span>{{bottom.key}}</span>
</div>
<div class="row">
<div class="col-lg-10">
<div class="progress">
<div class="progress-bar" role="progressbar"
[ngStyle]="{'width': bottom.value > 0 ? bottom.value + '%' : '8px'}"></div>
<span class="percentage-value">{{bottom.value}}</span>
</div>
</div>
</div>
</div>
</div>
</div>
Screenshot to the desired outcome
In my CSS;
.journey-card-bottom {
border: 1px solid #DADCDD;
box-sizing: border-box;
padding: 10px;
line-height: 3;
width: 100%;
height: 435px;
}
.progress {
background-color: white !important;
margin-top: 5px;
}
.progress-bar {
border-radius: 0.25rem;
height: 8px;
align-self: center;
background-color: #0B4886;
}
.journey-card-bottom .progress-bar:nth-of-type(1) {
background-color: #68D391;
}
.journey-card-bottom .progress-bar:nth-of-type(2) {
background-color: #FCAF65;
}
It seems :nth-of-type(1) changes the background color but not only for 1st bar, for all of them.
:nth-of-type(2)does not effect at all i guess because there is no direct parent-child relation between each other.
On the other hand i know i can achieve with using [ngStyle] based on the item index in [ngFor] however i'm not sure if it's the best practice or not.
:nth-of-type() applies to sibling elements. Since .progress-bar is the first sibling within .progress and has no other siblings with the class .progress-bar, only the styles declared in .journey-card-bottom .progress-bar:nth-of-type(1) will be applied. Here is a code snippet showing your CSS working by changing the HTML structure:
.journey-card-bottom {
border: 1px solid #DADCDD;
box-sizing: border-box;
padding: 10px;
line-height: 3;
width: 100%;
height: 435px;
}
.progress {
background-color: white !important;
margin-top: 5px;
}
.progress-bar {
border-radius: 0.25rem;
height: 8px;
align-self: center;
background-color: #0B4886;
}
.journey-card-bottom .progress-bar:nth-of-type(1) {
background-color: #68D391;
}
.journey-card-bottom .progress-bar:nth-of-type(2) {
background-color: #FCAF65;
}
<div class="journey-card-bottom">
<div class="progress">
<div class="progress-bar" role="progressbar"></div>
<span class="percentage-value">90</span>
<div class="progress-bar" role="progressbar"></div>
<span class="percentage-value">60</span>
</div>
</div>
To solve your issue, I would suggest using :nth-of-type() on the top-level element of the for loop. In the below example, the top-level element has the class .target-class:
.journey-card-bottom {
border: 1px solid #DADCDD;
box-sizing: border-box;
padding: 10px;
line-height: 3;
width: 100%;
height: 435px;
}
.progress {
background-color: white !important;
margin-top: 5px;
}
.progress-bar {
border-radius: 0.25rem;
height: 8px;
align-self: center;
background-color: #0B4886;
}
.target-class:nth-of-type(1) .progress-bar {
background-color: #68D391;
}
.target-class:nth-of-type(2) .progress-bar {
background-color: #FCAF65;
}
<!-- Rendered HTML from the component -->
<div class="row">
<div class="journey-card-bottom">
<div class="target-class">
<div>
<span>Passed</span>
</div>
<div class="row">
<div class="col-lg-10">
<div class="progress">
<div class="progress-bar" role="progressbar"></div>
<span class="percentage-value">90</span>
</div>
</div>
</div>
</div>
<div class="target-class">
<div>
<span>Referred</span>
</div>
<div class="row">
<div class="col-lg-10">
<div class="progress">
<div class="progress-bar" role="progressbar"></div>
<span class="percentage-value">60</span>
</div>
</div>
</div>
</div>
</div>
</div>

How to animate an already existing skill bar

I already have a skill bar created on my page, but I was wondering if there was a way to animate it, so that when you scroll to that area the bar extends out from nothing to the full length of the bar. Here is my html for the bar:
<div id="skills_skill">
<div class="col-xs-12 col-md-4" id='skills_text'>
Example Skill
</div>
<div class="col-xs-12 col-md-8" id='skills_container'>
<div class="skills example">90%</div>
</div>
</div>
And here is the css:
#skills_text {
font-weight: bold;
border-right: 1px solid white;
}
.skills {
text-align: right;
padding-right: 20px;
line-height: 20px;
color: black;
border-radius: 20px;
}
.example {
width: 90%;
background-color: white;
}
I assume you use Bootstrap 4. I will use Bootstrap progress component for this example. This snippet code only for the progress bar animation. You should use javascript to keep track of your scroll position to trigger the animation. Please let me know if you need help
.progress-bar {
animation: progress 300ms ease-in-out;
animation-fill-mode: forwards;
}
#keyframes progress {
0% {
width: 0;
}
100% {
width: 100%;
}
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="progress">
<div class="progress-bar" role="progressbar" aria- valuenow="25" aria-valuemin="0" aria-valuemax="100"> </div>
</div>

Elements are overlapping each other even though I use twitter bootstrap

I am using twitter bootstrap on my site, I noticed that elements are overlapping if I make my window smaller. This does not look nice and I thought twitter bootstrap should make my website full responsive on all sizes.
<div class="main row">
<div class="col-sm-6">
<center><h3>Firmware Download</h3></center>
<!-- Main Buttons -->
<div class="row">
<div class="col-sm-6">
<button class="mainButtons" id="downloadFW">Download newest firmware to the server</button>
<button class="mainButtons" id="reboot">Reboot server</button>
</div>
<div class="col-sm-6">
<button class="mainButtons" id="deleteLogfile">Delete logfile</button>
<button class="mainButtons" id="deleteTemplateStatusFile">Delete status file</button>
</div>
</div>
<!-- Template Generierung -->
<div class="templateButtons col-sm-12">
<h4>Create Template</h4>
<select id="firmwareTemplate">
<option value="mb">MB</option>
<option value="bm">BM</option>
</select>
<select id="fileType">
<option value="ova">OVA</option>
<option value="vhd">VHD</option>
</select>
<button id="generateTemplate">Template erstellen</button>
</div>
</div>
<div class="codeBox col-sm-6">
<h5>Ausgabe:</h5>
<pre id="codeOutput">-</pre>
</div>
</div>
CSS:
body {
margin: 20px;
}
.codeBox {
border: 1px solid black;
overflow-y: scroll;
}
.codeBox code {
/* Styles in here affect the text of the codebox */
font-size:0.9em;
/* You could also put all sorts of styling here, like different font, color, underline, etc. for the code. */
}
.lineTop {
height: 1px;
background-color: #D8D8D8;
margin-top: 20px;
}
.lineBottom {
height: 1px;
background-color: #D8D8D8;
margin-bottom: 20px;
}
.lineNoMargin {
height: 2px;
background-color: #D8D8D8;
}
.main {
height: 350px;
margin-left: 20px;
}
.mainButtons {
min-width: 300px;
text-align:left;
}
.templateButtons {
margin-top: 50px;
margin-left: 12px;
}
#templateStatusOutput {
min-height: 240px;
}
#deleteTemplateStatusFile {
visibility: hidden;
}
.statusBarContainer {
border: 1px solid #D8D8D8;
padding-right: 0;
padding-left: 0;
}
.statusBar {
height: 20px;
background-color: #5cb85c;
width: 0;
color: white;
}
#statusBarTemplateStatus {
background-color: green;
}
#statusBarCopyStatus {
background-color: orangered;
}
.makeSpace50 {
height: 50px;
}
#statusBar1 {
visibility: hidden;
}
#statusBar2 {
visibility: hidden;
}
Is this my fault?
you use absolute value in your css, for example:
.mainButtons {
min-width: 300px;
text-align:left;
}
Try using relative value like percentage for example, so that the element can keep the bootstrap's responsiveness:
.mainButtons {
min-width: 100%;
text-align:left;
}
-------------- UPDATE -------------------
looking at your code here:
<div class="main row">
<div class="col-sm-6">
<center><h3>Firmware Download</h3></center>
<!-- Main Buttons -->
<div class="row">
<div class="col-sm-6">
<button class="mainButtons" id="downloadFW">Download newest firmware to the server</button>
<button class="mainButtons" id="reboot">Reboot server</button>
</div>
<div class="col-sm-6">
<button class="mainButtons" id="deleteLogfile">Delete logfile</button>
<button class="mainButtons" id="deleteTemplateStatusFile">Delete status file</button>
</div>
</div>
// ......
First you divide the screen into two part, <div class="main row"><div class="col-sm-6"> ...., then you divide again the first part of the screen into two again <!-- Main Buttons --><div class="row"><div class="col-sm-6">..., this mean the button only has 1/4 of your screen as its space. If that 1/4 space is less than 300px, as it is the min-width of your mainButtons, then your problem occured.

Layout progress bars in-between nodes - HTML & CSS

I'm trying to build a stepping wizard form layout with a bar at the top of the page containing a dynamic number of steps (nodes) and progress bars connecting the nodes. I'm having trouble getting the progress bars and nodes to cooperate.
The idea is to have each nodes spaced evenly on the page horizontally (already working nicely using flexbox), and the progress bars fluidly filling the gaps between the nodes.
I am currently trying to use an <li> to contain each iteration of the progress bar & <a> pairs, but it is not laying out like I need it to (the progress bars are not behaving fluidly and not filling empty space between the <a> tags).
Is this the best way to lay this out?
Just though I'd confirm this is the best way to lay these out before going any further.
EDIT 1 (Clarifying goal):
This image is an example of what I am trying to achieve.
The progress bar and red <a> node are both within the same <li>. I have given the progress bar a width of 90% for this example but the goal is to only assign a width to the red <a> node and have the project bar fluidly fill the remaining space.
Below is the HTML & SCSS I am currently using:
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-title">Project Milestones</div>
</div>
<div class="panel-body">
<ul class="milestone-bar">
<li>
<div class="progress project-progress">
<div class="progress-bar" role="progressbar" aria-valuenow="100.0" aria-valuemin="0" aria-valuemax="100" style="width: 100.0%;">
100%
</div>
</div>
Milestone 1
</li>
<li>
<div class="progress project-progress">
<div class="progress-bar" role="progressbar" aria-valuenow="100.0" aria-valuemin="0" aria-valuemax="100" style="width: 100.0%;">
100%
</div>
</div>
Milestone 3
</li>
<li>
<div class="progress project-progress">
<div class="progress-bar" role="progressbar" aria-valuenow="50.0" aria-valuemin="0" aria-valuemax="100" style="width: 50.0%;">
50%
</div>
</div>
Milestone 2
</li>
</ul>
</div>
</div>
ul.milestone-bar {
padding: 0;
margin: 0 0 15px 0;
display: flex;
li {
width: 100%;
list-style: none;
display: inline-block;;
a {
width: 30px;
height: 30px;
font-size: 12px;
border-radius: 15px;
background-color: red;
float:right;
&:hover {
background: none;
border: 4px solid blue;
}
&:active {
background-color: darkblue;
}
&:focus {
background-color: green;
}
}
.project-progress {
background-color: #d3d3d3;
display: inline-block;
margin: 0;
}
}
}
Is this on the right track?
Below is a snippet of the above:
ul.milestone-bar {
padding: 0;
margin: 0 0 15px 0;
display: flex;
}
ul.milestone-bar li {
width: 100%;
list-style: none;
display: inline-block;
}
ul.milestone-bar li a {
width: 30px;
height: 30px;
font-size: 12px;
border-radius: 15px;
background-color: red;
float: right;
}
ul.milestone-bar li a:hover {
background: none;
border: 4px solid blue;
}
ul.milestone-bar li a:active {
background-color: darkblue;
}
ul.milestone-bar li a:focus {
background-color: green;
}
ul.milestone-bar li .project-progress {
background-color: #d3d3d3;
display: inline-block;
margin: 0;
}
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-title">Project Milestones</div>
</div>
<div class="panel-body">
<ul class="milestone-bar">
<li>
<div class="progress project-progress">
<div class="progress-bar" role="progressbar" aria-valuenow="100.0" aria-valuemin="0" aria-valuemax="100" style="width: 100.0%;">
100%
</div>
</div>
Milestone 1
</li>
<li>
<div class="progress project-progress">
<div class="progress-bar" role="progressbar" aria-valuenow="100.0" aria-valuemin="0" aria-valuemax="100" style="width: 100.0%;">
100%
</div>
</div>
Milestone 3
</li>
<li>
<div class="progress project-progress">
<div class="progress-bar" role="progressbar" aria-valuenow="50.0" aria-valuemin="0" aria-valuemax="100" style="width: 50.0%;">
50%
</div>
</div>
Milestone 2
</li>
</ul>
</div>
</div>
So I did some changes to your code:
Added flex to each li to create nested flex children here:
ul.milestone-bar li {
width: 100%;
list-style: none;
display: flex;
}
Added flex: 1 for it to flex to the whole width and vertically align it to the center using align-self: center to your project-progress like this:
ul.milestone-bar li .project-progress {
background-color: #d3d3d3;
display: inline-block;
margin: 0;
flex: 1;
align-self: center
}
Added the progress bar style:
ul.milestone-bar li .project-progress .progress-bar {
background: #0095FF;
text-align: center;
}
Also adjusted the milestone-bar to look better:
ul.milestone-bar li a {
width: 60px;
height: 60px;
font-size: 10px;
border-radius: 50%;
background-color: red;
text-align: center;
line-height: 60px;
}
ul.milestone-bar li a:hover {
background: none;
border: 4px solid blue;
line-height: 52px;
}
To top it up, used box-sizing: border-box to all elements in the page for better management of border especially to remove the 'jumps' when you hover.
* {
box-sizing: border-box;
}
ul.milestone-bar {
padding: 0;
margin: 0 0 15px 0;
display: flex;
}
ul.milestone-bar li {
width: 100%;
list-style: none;
display: flex;
}
ul.milestone-bar li a {
width: 60px;
height: 60px;
font-size: 10px;
border-radius: 50%;
background-color: red;
text-align: center;
line-height: 60px;
}
ul.milestone-bar li a:hover {
background: none;
border: 4px solid blue;
line-height: 52px;
}
ul.milestone-bar li a:active {
background-color: darkblue;
}
ul.milestone-bar li a:focus {
background-color: green;
}
ul.milestone-bar li .project-progress {
background-color: #d3d3d3;
display: inline-block;
margin: 0;
flex: 1;
align-self: center
}
ul.milestone-bar li .project-progress .progress-bar {
background: #0095FF;
text-align: center;
}
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-title">Project Milestones</div>
</div>
<div class="panel-body">
<ul class="milestone-bar">
<li>
<div class="progress project-progress">
<div class="progress-bar" role="progressbar" aria-valuenow="100.0" aria-valuemin="0" aria-valuemax="100" style="width: 100.0%;">
100%
</div>
</div>
Milestone 1
</li>
<li>
<div class="progress project-progress">
<div class="progress-bar" role="progressbar" aria-valuenow="100.0" aria-valuemin="0" aria-valuemax="100" style="width: 100.0%;">
100%
</div>
</div>
Milestone 3
</li>
<li>
<div class="progress project-progress">
<div class="progress-bar" role="progressbar" aria-valuenow="50.0" aria-valuemin="0" aria-valuemax="100" style="width: 50.0%;">
50%
</div>
</div>
Milestone 2
</li>
</ul>
</div>
</div>
Let me know your feedback on this. Thanks!

bootstrap progress bar center of image and remove the gray above the progress bar

I'm using bootstrap progress bar and I want it in the center of the image. I also want to reduce the size of the progress bar remove the gray above the bar. I tried to explain it with the following picture:
https://i.stack.imgur.com/5ldHj.png
.progress-bar-gray {
background-color: #9A9A9A !important;
color: #F5F4F3 !important;
height: 2px !important;
border: 2px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<img src="http://lorempixel.com/320/170" class="img-responsive">
<div class="progress progress-striped active">
<div class="progress-bar progress-bar-gray" role="progressbar" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100" style="width: 50%">
</div>
</div>
I removed the "grey bar" by removing <div class="progress progress-striped active"></div> and put the image as a background image of a div so I could put the progress bar div inside and center it horizontally and vertically with position: absolute;. The full code is beow.
#image {
position: relative;
background-image: url(https://lorempixel.com/320/170);
width: 320px;
height: 170px;
}
.progress-bar-gray {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
background-color: #9A9A9A !important;
color: #F5F4F3 !important;
height: 2px !important;
border: 2px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div id="image">
<div class="progress-bar progress-bar-gray" role="progressbar" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100" style="width: 50%"></div>
</div>